/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #2d3748;
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    min-height: 100vh;
}

/* Arabic text styling */
.arabic, 
#answerRoot,
#answerPattern {
    font-family: 'Scheherazade New', serif;
    font-size: 1.3em;
    direction: rtl;
    text-align: center;
    line-height: 1.9;
    font-weight: 400;
}

/* Large Arabic word on flashcards - separate rule with higher specificity */
.arabic-word,
#arabicWord {
    font-family: 'Scheherazade New', serif;
    font-size: 5rem !important;
    direction: rtl;
    text-align: center;
    line-height: 1.4;
    font-weight: 500;
    margin-bottom: 1.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Layout */
.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    text-align: center;
    margin-bottom: 2rem;
    color: white;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 300;
}

.main-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Settings Panel */
.settings-panel {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 600px;
}

.settings-panel h3 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: #2d3748;
    text-align: center;
}

.setting-group {
    margin-bottom: 2rem;
}

.setting-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 1rem;
    color: #4a5568;
}

.form-checkboxes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.5rem;
}

.type-checkboxes {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
}

.form-checkboxes label,
.type-checkboxes label {
    display: flex;
    align-items: center;
    font-weight: 400;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.form-checkboxes input,
.type-checkboxes input {
    margin-right: 0.5rem;
    transform: scale(1.1);
}

.learning-mode-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.learning-mode-options label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: #ffffff;
}

.learning-mode-options label:hover {
    background-color: #f7fafc;
    border-color: #48bb78;
}

.learning-mode-options input[type="radio"]:checked + * {
    font-weight: 500;
}

.learning-mode-options label:has(input[type="radio"]:checked) {
    background-color: #f0fff4;
    border-color: #48bb78;
    color: #2f855a;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1rem;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(72, 187, 120, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(72, 187, 120, 0.5);
}

.btn-secondary {
    background: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background: #cbd5e0;
    transform: translateY(-1px);
}

.btn-success {
    background: #48bb78;
    color: white;
}

.btn-success:hover {
    background: #38a169;
    transform: translateY(-1px);
}

.btn-danger {
    background: #f56565;
    color: white;
}

.btn-danger:hover {
    background: #e53e3e;
    transform: translateY(-1px);
}

.btn-text {
    background: transparent;
    color: #48bb78;
    padding: 0.5rem 1rem;
}

.btn-text:hover {
    background: rgba(72, 187, 120, 0.1);
}

#startPractice {
    width: 100%;
    font-size: 1.1rem;
    padding: 1rem;
}

/* Flashcard Container */
.flashcard-container {
    width: 100%;
    max-width: 600px;
    background: white;
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
}

.stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding: 1rem;
    background: #f7fafc;
    border-radius: 8px;
    font-weight: 500;
    color: #4a5568;
}

/* Card Instructions */
.card-instructions {
    background: #f7fafc;
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    text-align: center;
    color: #4a5568;
}

.card-instructions p {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #2d3748;
}

.card-instructions ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    gap: 2rem;
    flex-wrap: wrap;
}

.card-instructions li {
    font-size: 0.95rem;
    color: #4a5568;
    position: relative;
}

.card-instructions li:before {
    content: "• ";
    margin-right: 0.5rem;
    color: #48bb78;
}

/* Flashcard */
.flashcard {
    background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
    border-radius: 12px;
    padding: 4rem 2rem;
    margin-bottom: 2rem;
    text-align: center;
    color: white;
    box-shadow: 0 8px 24px rgba(72, 187, 120, 0.3);
}





/* Answer Section */
.answer-section {
    background: #f7fafc;
    border-radius: 12px;
    padding: 2rem;
    margin-bottom: 2rem;
}

.answer-section h4 {
    color: #2d3748;
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.answer-details p {
    margin-bottom: 0.75rem;
    font-size: 1rem;
    color: #4a5568;
}

.answer-details strong {
    color: #2d3748;
    font-weight: 600;
}

.root-meaning {
    font-family: 'Inter', sans-serif;
    font-size: 0.8em;
    direction: ltr;
    font-weight: 400;
    color: #4a5568;
}

#answerRoot,
#answerPattern {
    font-size: 1.3rem;
    color: #48bb78;
    font-weight: 700;
}

/* Card Controls */
.card-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.practice-controls {
    display: flex;
    justify-content: space-between;
    border-top: 1px solid #e2e8f0;
    padding-top: 1rem;
}

/* Reference Table Overlay */
.reference-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.reference-modal {
    background: white;
    border-radius: 12px;
    width: 100%;
    max-width: 1200px;
    max-height: 90vh;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}

.reference-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem 2.5rem 2rem;
    border-bottom: 1px solid #e2e8f0;
    background: #f7fafc;
    position: relative;
    overflow: visible;
}

.reference-header h3 {
    margin: 0;
    color: #2d3748;
    font-size: 1.5rem;
}

.reference-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toggle-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toggle-label {
    font-size: 0.9rem;
    color: #4a5568;
    user-select: none;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #cbd5e0;
    transition: 0.3s ease;
    border-radius: 24px;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s ease;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .slider {
    background-color: #48bb78;
}

.toggle-switch input:checked + .slider:before {
    transform: translateX(20px);
}

.toggle-switch:hover .slider {
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

.toggle-switch input:checked + .slider:hover {
    background-color: #38a169;
}

/* Tooltip styling for the toggle switch */
.toggle-switch[title] {
    cursor: help;
    position: relative;
}

.toggle-switch[title]:hover {
    cursor: help;
}

/* Enhanced tooltip appearance - position below toggle to avoid clipping */
.toggle-switch[title]:hover:after {
    content: attr(title);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: #2d3748;
    color: white;
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
    z-index: 10000;
    margin-top: 0.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    max-width: 320px;
    text-align: center;
    white-space: normal;
    line-height: 1.3;
}

.toggle-switch[title]:hover:before {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: #2d3748;
    z-index: 10000;
    margin-top: 0.1rem;
}

.reference-content {
    padding: 0;
    overflow: hidden;
    max-height: calc(90vh - 80px);
    position: relative;
}

.table-container {
    overflow: auto;
    max-height: calc(90vh - 80px);
    position: relative;
}

.verb-forms-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    position: relative;
}

.verb-forms-table th {
    background: #48bb78;
    color: white;
    padding: 1rem 0.75rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    z-index: 20;
    border: 1px solid #38a169;
}

.verb-forms-table td {
    padding: 0.75rem;
    text-align: center;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: middle;
    border: 1px solid #e2e8f0;
}

/* Make the form number column (rightmost) sticky */
.verb-forms-table th:last-child,
.verb-forms-table td:last-child {
    position: -webkit-sticky;
    position: sticky;
    right: 0;
    z-index: 15;
    background: white;
    border-left: none;
    box-shadow: -2px 0 4px rgba(0, 0, 0, 0.1);
}

.verb-forms-table th:last-child {
    background: #48bb78;
    z-index: 25;
    border-left: none;
}

/* Add vertical divider as a pseudo-element on the sticky column */
.verb-forms-table td:last-child::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #38a169;
    z-index: 1;
}

.verb-forms-table th:last-child::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #2f855a;
    z-index: 1;
}

.verb-forms-table tr:nth-child(even) {
    background: #f7fafc;
}

.verb-forms-table tr:nth-child(even) td:last-child {
    background: #f7fafc;
}

.verb-forms-table tr:hover {
    background: #edf2f7;
}

.verb-forms-table tr:hover td:last-child {
    background: #edf2f7;
}

.verb-forms-table .form-number {
    font-weight: 600;
    color: #2d3748;
    background: inherit;
    font-size: 1rem;
    position: relative;
}

.verb-forms-table .arabic-pattern {
    font-family: 'Scheherazade New', serif;
    font-size: 1.1rem;
    font-weight: 500;
    color: #2d3748;
    direction: rtl;
}

/* Force proper Arabic letter joining even when letters are wrapped in spans */
.verb-forms-table .arabic-pattern span {
    display: inline;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
    font-feature-settings: "liga" 1, "calt" 1, "curs" 1, "kern" 1;
    font-variant-ligatures: contextual;
}

.verb-forms-table .not-available {
    color: #a0aec0;
    font-style: italic;
    font-size: 0.8rem;
}

/* Results Container */
.results-container {
    width: 100%;
    max-width: 600px;
    background: white;
    border-radius: 16px;
    padding: 3rem 2rem;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1);
    text-align: center;
}

.results-container h2 {
    color: #2d3748;
    margin-bottom: 2rem;
    font-size: 2rem;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
}

.stat-item {
    text-align: center;
}

.stat-number {
    display: block;
    font-size: 2.5rem;
    font-weight: 700;
    color: #48bb78;
    margin-bottom: 0.5rem;
}

.stat-label {
    font-size: 0.9rem;
    color: #718096;
    font-weight: 500;
}

.results-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Footer */
.footer {
    text-align: center;
    margin-top: 2rem;
    color: rgba(255,255,255,0.8);
    font-size: 0.9rem;
}

.footer .small {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-top: 0.5rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    .header {
        padding: 1rem 0;
        margin-bottom: 1rem;
    }
    
    .header h1 {
        font-size: 1.8rem;
        margin-bottom: 0.5rem;
    }
    
    .settings-panel,
    .flashcard-container,
    .results-container {
        padding: 1rem;
        flex: 1;
        display: flex;
        flex-direction: column;
    }
    
    .setting-group {
        margin-bottom: 1rem;
    }
    
    .setting-group label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }
    
    .form-checkboxes,
    .type-checkboxes {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.25rem;
    }
    
    .form-checkboxes label,
    .type-checkboxes label {
        font-size: 0.8rem;
        margin-bottom: 0.25rem;
    }
    
    .learning-mode-options {
        gap: 0.5rem;
    }
    
    .learning-mode-options label {
        padding: 0.5rem;
        font-size: 0.85rem;
    }
    
    .arabic-word,
    #arabicWord {
        font-size: 3.5rem !important;
        margin-bottom: 1rem;
    }
    
    .stats {
        font-size: 0.85rem;
        margin-bottom: 1rem;
    }
    
    .card-instructions {
        margin-bottom: 1rem;
    }
    
    .card-instructions p {
        font-size: 0.85rem;
        margin-bottom: 0.5rem;
    }
    
    .flashcard {
        padding: 2rem 1rem;
        margin-bottom: 1rem;
    }
    
    .answer-section {
        margin-bottom: 1rem;
    }
    
    .answer-details p {
        margin-bottom: 0.5rem;
        font-size: 0.9rem;
    }
    
    .root-meaning {
        font-size: 0.75em;
    }
    
    .card-controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .card-controls .btn {
        flex: 1;
        min-width: calc(50% - 0.25rem);
        padding: 0.6rem 0.5rem;
        font-size: 0.85rem;
    }
    
    .practice-controls {
        margin-top: auto;
        padding-top: 1rem;
        flex-direction: row;
        gap: 0.5rem;
    }
    
    .practice-controls .btn {
        flex: 1;
        padding: 0.6rem;
        font-size: 0.85rem;
    }
    
    .results-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .stat-item {
        padding: 0.75rem 0.5rem;
    }
    
    .stat-number {
        font-size: 1.5rem;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    .results-actions {
        flex-direction: row;
        gap: 0.5rem;
    }
    
    .results-actions .btn {
        flex: 1;
        padding: 0.75rem;
        font-size: 0.85rem;
    }
    
    .reference-modal {
        max-width: 95vw;
        max-height: 90vh;
        margin: 5vh auto;
    }
    
    .reference-header {
        padding: 0.75rem 1rem;
    }
    
    .reference-header h3 {
        font-size: 1.1rem;
    }
    
    .toggle-container {
        gap: 0.5rem;
    }
    
    .toggle-label {
        font-size: 0.8rem;
    }
    
    /* Hide color coding toggle on mobile - it doesn't work well with Arabic text rendering */
    .toggle-container {
        display: none;
    }
    
    .verb-forms-table {
        font-size: 0.8rem;
    }
    
    .verb-forms-table th {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
    }
    
    .verb-forms-table td {
        padding: 0.5rem 0.25rem;
    }
    
    .verb-forms-table .arabic-pattern {
        font-size: 1rem;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 5px;
    }
    
    .header {
        padding: 0.5rem 0;
        margin-bottom: 0.5rem;
    }
    
    .header h1 {
        font-size: 1.6rem;
        margin-bottom: 0.25rem;
    }
    
    .settings-panel,
    .flashcard-container,
    .results-container {
        padding: 0.75rem;
    }
    
    .setting-group {
        margin-bottom: 0.75rem;
    }
    
    .form-checkboxes {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.15rem;
    }
    
    .type-checkboxes {
        grid-template-columns: 1fr;
        gap: 0.15rem;
    }
    
    .form-checkboxes label,
    .type-checkboxes label {
        font-size: 0.75rem;
        margin-bottom: 0.15rem;
    }
    
    .learning-mode-options label {
        padding: 0.4rem;
        font-size: 0.8rem;
    }
    
    .arabic-word,
    #arabicWord {
        font-size: 2.8rem !important;
        margin-bottom: 0.75rem;
    }
    
    .flashcard {
        padding: 1.5rem 0.75rem;
        margin-bottom: 0.75rem;
    }
    
    .card-controls .btn {
        padding: 0.5rem 0.4rem;
        font-size: 0.8rem;
    }
    
    .practice-controls .btn {
        padding: 0.5rem;
        font-size: 0.8rem;
    }
    
    .results-stats {
        grid-template-columns: 1fr;
        gap: 0.4rem;
    }
    
    .stat-item {
        padding: 0.5rem;
    }
    
    .stat-number {
        font-size: 1.3rem;
    }
    
    .results-actions .btn {
        padding: 0.6rem;
        font-size: 0.8rem;
    }
}

/* Animation for card transitions */
.flashcard,
.answer-section {
    animation: slideIn 0.3s ease-out;
}

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

/* Focus styles for accessibility */
.btn:focus,
input[type="checkbox"]:focus {
    outline: 2px solid #48bb78;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn-primary {
        background: #000;
        border: 2px solid #000;
    }
    
    .flashcard {
        background: #000;
        border: 2px solid #000;
    }
}