/* General Styling */
body {
    font-family: 'Georgia', serif;
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
}

.quran-ui {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 20px;
    max-width: 1100px;
    margin: 20px auto;
    align-items: flex-start;
    background: url('https://www.transparenttextures.com/patterns/arabesque.png') repeat, #FFFFF0;
    background-size: 200px;
    background-blend-mode: overlay;
    border: 2px solid #D4A017;
    border-radius: 10px;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
}

.quran-header {
    font-family: 'Amiri', serif;
    font-size: 24px;
    color: #D4A017;
    text-align: center;
    background: linear-gradient(90deg, #006400, #D4A017);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 15px;
    padding: 10px;
    border-bottom: 1px dashed #D4A017;
}

/* Surah Panel */
.surah-panel {
    width: 20%;
    min-width: 250px;
    background: #f1f3f5;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    min-height: 280px;
    max-height: 70vh;
    box-sizing: border-box;
}

.surah-list {
    width: 100%;
    list-style: none;
    padding: 0;
}

.surah-item {
    padding: 10px;
    margin-bottom: 5px;
    background: #fff;
    border: 2px solid #D4A017;
    border-radius: 5px;
    font-family: 'Georgia', serif;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: block;
    width: 100%;
    min-height: 30px;
    overflow-wrap: break-word;
    box-sizing: border-box;
    white-space: normal;
}

.surah-item:hover, .surah-item.selected {
    background: #D4A017;
    color: #fff;
    transform: scale(1.02);
    box-shadow: 0 4px 10px rgba(212, 160, 23, 0.5);
}

.surah-dropdown {
    display: none; /* Hidden by default, shown on mobile */
    max-width: 100%;
    width: auto;
    min-width: 250px; /* Make dropdown wider */
    padding: 10px;
    margin: 0;
    border: 2px solid #D4A017;
    border-radius: 5px;
    font-size: 16px;
    font-family: 'Georgia', serif;
    background: #fff;
    box-shadow: 0 2px 5px rgba(212, 160, 23, 0.3);
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%23D4A017" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    box-sizing: border-box;
}

.surah-dropdown:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 10px rgba(212, 160, 23, 0.5);
}

/* Verse Panel */
.verse-container {
    flex: 1;
    min-width: 400px;
    background: #f8f9fa;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
    height: auto;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    overflow-x: hidden; /* Prevent horizontal overflow */
}

.dropdown {
    max-width: 100%;
    width: auto;
    min-width: 250px; /* Make dropdown wider */
    padding: 10px;
    margin: 0;
    border: 2px solid #D4A017;
    border-radius: 5px;
    font-size: 16px;
    font-family: 'Georgia', serif;
    background: #fff;
    box-shadow: 0 2px 5px rgba(212, 160, 23, 0.3);
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="%23D4A017" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 10px center;
    box-sizing: border-box;
}

.dropdown:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 10px rgba(212, 160, 23, 0.5);
}

.dropdown::-ms-expand {
    display: none;
}

.loading-spinner {
    display: none;
    font-size: 18px;
    color: #006400;
    text-align: center;
}

@keyframes fadeDots {
    0% { opacity: 0; }
    33% { opacity: 1; }
    66% { opacity: 1; }
    100% { opacity: 0; }
}

.loading-spinner span {
    animation: fadeDots 1.5s infinite;
}

.loading-spinner span:nth-child(2) {
    animation-delay: 0.5s;
}

.loading-spinner span:nth-child(3) {
    animation-delay: 1s;
}

.verse-display {
    width: 100%;
    max-width: 90%; /* Constrain to match verse-container */
    display: block;
    box-sizing: border-box;
}

.verse-card {
    display: block; /* Allow vertical growth */
    width: auto; /* Allow content-based width */
    max-width: 90%; /* Constrain to 90% of parent */
    margin: 0 auto; /* Center the card */
    padding: 5px;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    border: 1px solid transparent;
    background: #fff;
    box-sizing: border-box;
    height: auto; /* Allow height to grow */
    overflow-wrap: break-word; /* Ensure text wraps */
    word-break: break-all; /* Force break on any character if needed */
    white-space: normal; /* Ensure text wraps */
}

.verse-card:hover {
    transform: scale(1.01);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
    border-color: #D4A017;
}

.arabic-card {
    border-left: 2px solid #6c757d;
    background: #f1f3f5;
}

.hindi-card {
    border-left: 2px solid #007BFF;
    background: #f8f9fa;
}

.english-card {
    border-left: 2px solid #28a745;
    background: #e9ecef;
}

.arabic-card p {
    font-family: 'Amiri', serif;
    font-size: 16px;
    font-weight: bold;
    color: #333;
    direction: rtl;
    text-align: right; /* Ensure proper alignment for RTL */
    margin: 0;
    padding-inline-start: 10px;
    padding-inline-end: 10px;
    line-height: 1.6;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-all; /* Force break for lengthy Arabic text */
}

.hindi-card p {
    font-family: 'Noto Sans Devanagari', sans-serif;
    font-size: 14px;
    font-weight: bold;
    color: #222;
    margin: 0;
    padding-inline-start: 10px;
    padding-inline-end: 10px;
    line-height: 1.6;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-all; /* Force break for lengthy Hindi text */
}

.english-card p {
    font-family: 'Georgia', serif;
    font-size: 12px;
    font-style: italic;
    color: #666;
    margin: 0;
    padding-inline-start: 10px;
    padding-inline-end: 10px;
    line-height: 1.6;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: break-all; /* Force break for lengthy English text */
}

/* Responsive Design */
@media (max-width: 768px) {
    .quran-ui {
        flex-direction: column;
        gap: 15px;
        padding: 10px;
        margin: 10px auto;
        max-width: 100%;
        align-items: stretch;
    }

    .surah-panel {
        flex: 1;
        min-width: 0;
        max-width: 90%;
        width: auto;
        margin: 0 auto;
        padding: 10px;
        height: auto; /* Allow height to adjust to content */
        min-height: 0; /* Remove any min-height to avoid excess space */
        max-height: none;
        overflow-y: visible;
    }

    .surah-list {
        display: none; /* Hide the list on mobile */
    }

    .surah-dropdown {
        display: block; /* Show dropdown on mobile */
        max-width: 100%;
        width: auto;
        min-width: 250px; /* Make dropdown wider */
        font-size: 14px;
        padding: 8px 25px 8px 8px;
        margin: 0;
        background-position: right 8px center;
    }

    .verse-container {
        flex: 1;
        min-width: 0;
        max-width: 90%;
        width: auto;
        margin: 0 auto;
        padding: 10px;
        height: auto;
        justify-content: flex-start;
        overflow-x: hidden; /* Prevent horizontal overflow */
    }

    .quran-header {
        font-size: 20px;
        padding: 5px;
        margin-bottom: 5px;
    }

    .dropdown {
        max-width: 100%;
        width: auto;
        min-width: 250px; /* Make dropdown wider */
        font-size: 14px;
        padding: 8px 25px 8px 8px;
        margin: 0;
        background-position: right 8px center;
    }

    .loading-spinner {
        font-size: 16px;
    }

    .verse-display {
        display: grid; /* Use grid for mobile */
        grid-template-columns: minmax(0, 300px); /* Fixed max width for cards */
        justify-content: center; /* Center the grid items */
        gap: 10px; /* Space between cards */
        width: 100%;
        max-width: 100%; /* Ensure it fits within verse-container */
    }

    .verse-card {
        width: 100%; /* Fit within grid column */
        max-width: 100%; /* Respect grid column width */
        margin: 0; /* Remove auto margin, grid handles centering */
        padding: 5px;
        height: auto; /* Allow height to grow */
    }

    .arabic-card p {
        font-size: 14px;
        padding-inline-start: 8px;
        padding-inline-end: 8px;
    }

    .hindi-card p {
        font-size: 12px;
        padding-inline-start: 8px;
        padding-inline-end: 8px;
    }

    .english-card p {
        font-size: 12px;
        padding-inline-start: 8px;
        padding-inline-end: 8px;
    }
}

@media (max-width: 480px) {
    .quran-ui {
        gap: 10px;
        padding: 5px;
        margin: 5px auto;
    }

    .surah-panel {
        padding: 5px;
        max-width: 95%;
        height: auto; /* Allow height to adjust to content */
        min-height: 0; /* Remove any min-height to avoid excess space */
    }

    .surah-dropdown {
        font-size: 12px;
        padding: 6px 20px 6px 6px;
        background-position: right 6px center;
        min-width: 220px; /* Slightly smaller for smaller screens */
    }

    .verse-container {
        padding: 5px;
        max-width: 95%;
    }

    .quran-header {
        font-size: 18px;
        padding: 3px;
        margin-bottom: 3px;
    }

    .dropdown {
        font-size: 12px;
        padding: 6px 20px 6px 6px;
        background-position: right 6px center;
        min-width: 220px; /* Slightly smaller for smaller screens */
    }

    .loading-spinner {
        font-size: 14px;
    }

    .verse-display {
        grid-template-columns: minmax(0, 280px); /* Slightly smaller for smaller screens */
        gap: 8px;
    }

    .verse-card {
        padding: 4px;
    }

    .arabic-card p {
        font-size: 12px;
        padding-inline-start: 6px;
        padding-inline-end: 6px;
    }

    .hindi-card p {
        font-size: 11px;
        padding-inline-start: 6px;
        padding-inline-end: 6px;
    }

    .english-card p {
        font-size: 11px;
        padding-inline-start: 6px;
        padding-inline-end: 6px;
    }
}

@media (max-width: 360px) {
    .quran-ui {
        gap: 8px;
        padding: 3px;
        margin: 3px auto;
    }

    .surah-panel {
        padding: 3px;
        max-width: 98%;
        height: auto; /* Allow height to adjust to content */
        min-height: 0; /* Remove any min-height to avoid excess space */
    }

    .surah-dropdown {
        font-size: 10px;
        padding: 4px 15px 4px 4px;
        background-position: right 4px center;
        background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 24 24" fill="none" stroke="%23D4A017" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
        min-width: 200px; /* Adjusted for very small screens */
    }

    .verse-container {
        padding: 3px;
        max-width: 98%;
    }

    .quran-header {
        font-size: 16px;
        padding: 2px;
        margin-bottom: 2px;
    }

    .dropdown {
        font-size: 10px;
        padding: 4px 15px 4px 4px;
        background-position: right 4px center;
        background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="8" height="8" viewBox="0 0 24 24" fill="none" stroke="%23D4A017" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
        min-width: 200px; /*_phi Adjusted for very small screens */
    }

    .loading-spinner {
        font-size: 12px;
    }

    .verse-display {
        grid-template-columns: minmax(0, 260px); /* Even smaller for very small screens */
        gap: 6px;
    }

    .verse-card {
        padding: 3px;
    }

    .arabic-card p {
        font-size: 11px;
        padding-inline-start: 4px;
        padding-inline-end: 4px;
    }

    .hindi-card p {
        font-size: 10px;
        padding-inline-start: 4px;
        padding-inline-end: 4px;
    }

    .english-card p {
        font-size: 10px;
        padding-inline-start: 4px;
        padding-inline-end: 4px;
    }
}