:root {
    /* Refined color palette with more sophisticated tones */
    --primary-color: #17717a;
    --secondary-color: #9ccfd8;
    --accent-color: #0a4950;
    --text-color: #2d3748;
    --background-color: #f8fafc;
    --card-color: #ffffff;
    --hover-color: #edf6f9;
    --border-color: #e2e8f0;
    --border-radius: 10px;
    --box-shadow: 0 4px 12px rgba(0, 0, 0, 0.04);
    --transition: all 0.3s ease;
}

body.dark-theme {
    --primary-color: #4fd1dc;
    --secondary-color: #2f8f99;
    --accent-color: #8fe3ea;
    --text-color: #e2e8f0;
    --background-color: #0f1a1c;
    --card-color: #16262a;
    --hover-color: #1c2f33;
    --border-color: #26393d;
    --box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

body,
.verse-card,
.mood-btn,
.mood-search,
.verses-container,
.search-container,
.verse-reflection,
.theme-toggle {
    transition: background-color 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    /* More subtle gradient background */
    background-image: linear-gradient(150deg, rgba(156, 207, 216, 0.05), rgba(23, 113, 122, 0.03));
    overflow-y: auto; /* Ensure scrolling works properly */
}

.container {
    max-width: 800px;  /* Slightly narrower for better readability */
    margin: 0 auto;
    padding: 2.5rem 2rem;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Add these properties to ensure footer stays at bottom */
    position: relative;
    flex: 1;
    /* Ensure content doesn't cause jumps */
    overflow-x: hidden;
    width: 100%;
    height: auto;
}

header {
    text-align: center;
    margin-bottom: 3.5rem;
    color: var(--accent-color);
    position: relative;
}

header:after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 2px;
    background: linear-gradient(to right, transparent, var(--primary-color), transparent);
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    letter-spacing: 1.5px;
    font-weight: 600;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.75;
    font-weight: 300;
    letter-spacing: 0.7px;
}

.mood-section {
    margin-bottom: 2rem; /* Reduce space to prevent overflow */
    position: relative;
    z-index: 1;
}

h2 {
    text-align: center;
    margin-bottom: 1.8rem;
    color: var(--primary-color);
    font-weight: 500;
    font-size: 1.4rem;
    letter-spacing: 0.3px;
}

.search-container {
    display: flex;
    margin-bottom: 1.5rem;
    width: 100%;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
    border-radius: var(--border-radius);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.03);
    border: 1px solid var(--border-color);
}

.mood-search {
    flex-grow: 1;
    padding: 0.9rem 1.2rem;
    border: none;
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
    background-color: var(--card-color);
    color: var(--text-color);
}

.mood-search::placeholder {
    color: #a0aec0;
}

.mood-search:focus {
    box-shadow: 0 0 0 2px var(--secondary-color);
}

.search-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.search-btn:hover {
    background-color: var(--accent-color);
}

.or-divider {
    text-align: center;
    margin: 2rem 0 1.5rem;
    color: #718096;
    opacity: 0.8;
    position: relative;
    font-size: 0.9rem;
    font-weight: 400;
}

.or-divider::before, .or-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 80px;
    height: 1px;
    background-color: var(--border-color);
}

.or-divider::before {
    left: calc(50% - 100px);
}

.or-divider::after {
    right: calc(50% - 100px);
}

.mood-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.8rem;
    /* Prevent resizing */
    margin-bottom: 1rem;
    width: 100%;
}

.mood-btn {
    background-color: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.9rem 0.7rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    font-family: 'Poppins', sans-serif;
    color: var(--primary-color);
    font-weight: 500;
    font-size: 0.9rem;
    letter-spacing: 0.2px;
    /* Ensure fixed height */
    min-height: 2.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 3rem; /* Fixed height for all mood buttons */
    min-height: 3rem;
    width: 100%; /* Take full width of grid cell */
    box-sizing: border-box;
}

.mood-btn:hover {
    background-color: var(--hover-color);
    transform: translateY(-2px);
    box-shadow: var(--box-shadow);
    border-color: var(--secondary-color);
}

.verses-container {
    background-color: var(--card-color);
    border-radius: var(--border-radius);
    padding: 0.5rem;
    box-shadow: var(--box-shadow);
    margin-bottom: 2rem;
    min-height: 250px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    border: 1px solid var(--border-color);
    /* Prevent content jumps by setting consistent dimensions */
    width: 100%;
    position: relative;
    height: auto;
    transition: min-height 0.3s ease; /* Smooth transition when height changes */
    min-height: 300px; /* Increased minimum height */
    transition: none; /* Remove transitions that could cause jumps */
    height: auto !important; /* Force height to be auto and override any inline styles */
}

.verses-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 0.5rem;
    /* Allow content to grow */
    height: auto;
    min-height: 100px;
    margin-bottom: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    width: 100%;
    position: relative;
}

.verse-card {
    padding: 2rem;
    border-radius: var(--border-radius);
    background-color: var(--card-color);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border-color);
    transition: var(--transition);
    width: 100%;
    height: auto;
    min-height: 100px;
    /* Prevent content jumps */
    box-sizing: border-box;
}

.verse-card:hover {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.06);
    transform: translateY(-2px);
}

.verse-card:before {
    content: '"';
    position: absolute;
    top: 15px;
    left: 15px;
    font-size: 4rem;
    color: rgba(23, 113, 122, 0.07);
    font-family: 'Georgia', serif;
    line-height: 1;
}

.verse-text {
    font-family: 'Amiri', serif;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    line-height: 1.8;
    color: var(--accent-color);
    position: relative;
    padding: 0 0.5rem 0 1.5rem;
}

.verse-arabic {
    font-family: 'Amiri', serif;
    font-size: 1.7rem;
    margin: 1.5rem 0;
    line-height: 2;
    color: var(--accent-color);
    direction: rtl;
    text-align: center;
    opacity: 0.9;
}

.verse-reference {
    font-style: italic;
    margin-bottom: 1.5rem;
    color: var (--primary-color);
    font-size: 1rem;
    opacity: 0.85;
}

.verse-reflection {
    background-color: var(--hover-color);
    padding: 1.2rem 1.5rem;
    border-radius: var(--border-radius);
    margin-top: 1.5rem;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-color);
    position: relative;
    border-left: 3px solid var(--secondary-color);
}

.loader {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100px;
    width: 100%;
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
}

.spinner {
    width: 45px;
    height: 45px;
    border: 4px solid rgba(23, 113, 122, 0.1);
    border-radius: 50%;
    border-top-color: var (--primary-color);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.verse-card {
    animation: fadeInUp 0.45s ease both;
}

.verse-card:nth-child(2) { animation-delay: 0.08s; }
.verse-card:nth-child(3) { animation-delay: 0.16s; }
.verse-card:nth-child(4) { animation-delay: 0.24s; }
.verse-card:nth-child(5) { animation-delay: 0.32s; }

@media (prefers-reduced-motion: reduce) {
    .verse-card {
        animation: none;
    }
}

.theme-toggle {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background-color: var(--card-color);
    color: var(--primary-color);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--box-shadow);
    z-index: 10;
}

.theme-toggle:hover {
    transform: translateY(-2px) rotate(10deg);
    border-color: var(--secondary-color);
}

.theme-toggle:focus-visible,
.mood-btn:focus-visible,
.search-btn:focus-visible,
.mood-search:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
    height: 0 !important;
    visibility: hidden;
}

footer {
    text-align: center;
    margin-top: auto;
    padding: 2rem 0 1rem;
    color: var(--primary-color);
    font-size: 0.85rem;
    opacity: 0.7;
    /* Ensure footer is always visible */
    position: relative;
    width: 100%;
}

.footer-link {
    color: var(--primary-color);
    text-decoration: none;
    border-bottom: 1px dotted var(--primary-color);
    padding-bottom: 1px;
    transition: var(--transition);
}

.footer-link:hover {
    color: var(--accent-color);
    border-bottom-color: var(--accent-color);
}

/* Styles for More Emotions section */
.more-emotions-container {
    text-align: center;
    margin-top: 1.2rem;
}

.more-emotions-btn {
    background-color: transparent;
    color: var(--primary-color);
    border: none;
    padding: 0.6rem 1rem;
    border-radius: var(--border-radius);
    font-family: 'Poppins', sans-serif;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var (--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.more-emotions-btn:hover {
    background-color: var(--hover-color);
    transform: translateY(-1px);
}

.more-emotions-btn i {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.more-emotions-btn:hover i {
    transform: translateY(1px);
}

.more-emotions-grid {
    margin-top: 1rem;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.8rem;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.more-emotions-grid.hidden {
    display: none;
}

/* Suggested moods styling */
.suggested-moods {
    margin-top: 1.5rem;
    text-align: center;
}

.suggested-moods p {
    margin-bottom: 0.8rem;
    font-weight: 500;
    color: var(--primary-color);
    font-size: 0.9rem;
}

.mood-grid.suggested {
    grid-template-columns: repeat(4, 1fr);
    max-width: 500px;
    margin: 0 auto;
    gap: 0.7rem;
}

.suggested-mood {
    background-color: var(--hover-color);
    color: var(--primary-color);
    font-weight: 500;
    padding: 0.5rem 0.3rem;
    border-radius: var(--border-radius);
    border: 1px solid var(--secondary-color);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
}

.suggested-mood:hover {
    background-color: var(--primary-color);
    color: white;
}

/* Error message styling */
.verse-reflection ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.verse-reflection ul li {
    margin-bottom: 0.5rem;
}

/* Media Queries for Responsive Design */
@media (max-width: 992px) {
    .mood-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .or-divider::before {
        left: calc(50% - 90px);
        width: 70px;
    }

    .or-divider::after {
        right: calc(50% - 90px);
        width: 70px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1.5rem;
    }
    
    h1 {
        font-size: 2.2rem;
    }
    
    .mood-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .verse-text {
        font-size: 1.3rem;
    }
    
    .verse-arabic {
        font-size: 1.5rem;
    }
    
    .more-emotions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .mood-grid.suggested {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .container {
        padding: 1rem 1rem 5rem; /* Add extra padding at the bottom */
    }
    
    h1 {
        font-size: 2rem;
    }
    
    .subtitle {
        font-size: 0.95rem;
    }
    
    .search-container {
        flex-direction: row;
    }
    
    .mood-search {
        border-radius: 0;
    }
    
    .search-btn {
        border-radius: 0;
    }
    
    .or-divider::before, .or-divider::after {
        width: 40px;
    }
    
    .or-divider::before {
        left: calc(50% - 60px);
    }

    .or-divider::after {
        right: calc(50% - 60px);
    }
    
    .verse-text {
        font-size: 1.2rem;
        padding: 0;
    }
    
    .verse-arabic {
        font-size: 1.3rem;
    }
    
    .verse-card {
        padding: 1.5rem;
        margin-bottom: 0.5rem;
    }
    
    .verse-card:before {
        font-size: 3rem;
        top: 10px;
        left: 10px;
    }
    
    /* Fix footer for mobile devices */
    footer {
        padding: 1.5rem 0;
        margin-top: 2rem;
    }
}

/* Add new styles to fix position issues */
html, body {
    overflow-x: hidden;
    position: relative;
}

/* Add styles for maintaining consistency during loading state */
.loading-state {
    position: relative;
    min-height: 250px;
}
