/* Proton Design System Colors */
:root {
    /* Light Theme (Default) */
    --purple-primary: #6d4aff;
    --purple-hover: #5a3fd6;
    --purple-light: #f0ebff;
    --text-primary: #191c1f;
    --text-secondary: #586069;
    --border-color: #e4e6e8;
    --background: #ffffff;
    --surface-bg: #f8f9fa;
    --success: #00b34d;
    --error: #e0184d;
    --focus-ring: rgba(109, 74, 255, 0.4);
    --number-badge-bg: #e4e6e8;
    --number-badge-text: #586069;
    --word-display-bg: #ffffff;
    --word-display-border: #e4e6e8;
}

/* Dark Theme - FIXED CONTRAST */
@media (prefers-color-scheme: dark) {
    :root {
        --purple-primary: #8c6aff;
        --purple-hover: #9d7fff;
        --purple-light: #24203f;
        --text-primary: #f5f5f5;
        --text-secondary: #b0b5bc;
        --border-color: #3a3f45;
        --background: #191c1f;
        --surface-bg: #2a2e33;
        --success: #00d46a;
        --error: #ff5c7a;
        --focus-ring: rgba(140, 107, 255, 0.5);
        --number-badge-bg: #3a3f45;
        --number-badge-text: #a0a4aa;
        --word-display-bg: #ffffff;
        --word-display-border: #d0d0d0;
    }
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--background);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Global Link Styling */
a {
    color: var(--purple-primary);
    text-decoration: none;
    text-underline-offset: 2px;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--purple-hover);
    text-decoration: underline;
}

/* Language Dropdown Menu (Proton Style) */
.language-dropdown-container {
    position: relative;
    display: inline-block;
}

.language-dropdown-btn {
    background: transparent;
    border: none;
    color: var(--purple-primary);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.language-dropdown-btn:hover {
    background-color: var(--purple-light);
}

.language-dropdown-btn:focus-visible {
    outline: 2px solid var(--purple-primary);
    outline-offset: 2px;
}

.language-dropdown-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    right: 0;
    min-width: 200px;
    background-color: var(--background);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 0.5rem;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 1000;
}

.language-menu-open .language-dropdown-menu {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.language-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.9375rem;
    text-align: left;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.language-option .emoji {
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
}

.language-option:hover {
    background-color: var(--surface-bg);
}

.language-option:focus-visible {
    outline: 2px solid var(--purple-primary);
    outline-offset: -2px;
}

.language-option-active {
    color: var(--purple-primary);
    font-weight: 600;
}

.language-option-active::after {
    content: '✓';
    margin-left: auto;
    color: var(--purple-primary);
}

.language-reset-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    text-align: center;
    cursor: pointer;
    border-radius: 8px;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.75rem;
    transition: all 0.2s ease;
}

.language-reset-btn:hover {
    color: var(--purple-primary);
    background-color: var(--purple-light);
}

/* RIGHT-TO-LEFT (RTL) LANGUAGE SUPPORT - Arabic & Others     */

/* Arabic - Right-aligned layout with flipped direction */
.language-option[data-lang="ar"] {
    text-align: right;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Arabic flag - always visible on left side */
.language-option[data-lang="ar"] .emoji {
    margin-left: 0;
    order: -1;  /* Force emoji to leftmost position */
}

/* Arabic checkmark - move to LEFT side for RTL */
.language-option-active[data-lang="ar"]::after {
    content: '✓';
    margin-right: 0;
    margin-left: auto;  /* Push to left (since it's RTL) */
    color: var(--purple-primary);
    order: 1;  /* Place after text */
}

/* Override checkmark position - ensure it's on correct side */
.language-option-active[data-lang="ar"] {
    position: relative;
}

.language-option-active[data-lang="ar"]::after {
    position: absolute;
    left: 0.75rem;
    right: auto;
    top: 50%;
    transform: translateY(-50%);
    order: -2;  /* Before everything else */
    margin-right: 0;
    margin-left: 0;
}

/* Arabic dropdown menu - RTL-aware */
.language-dropdown-menu[data-lang="ar"] {
    direction: rtl;
}

/* Arabic reset button - RTL aware */
.language-reset-btn[data-lang="ar"] {
    direction: rtl;
    text-align: right;
}

.language-separator {
    color: var(--text-secondary);
    margin: 0 0.5rem;
    font-weight: 500;
    white-space: nowrap;
}

/* Accessibility - Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus Styles */
:focus-visible {
    outline: 3px solid var(--purple-primary);
    outline-offset: 2px;
}

/* Container */
.container {
    max-width: 680px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Screens */
.screen {
    display: none;
    width: 100%;
    text-align: center;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

/* Typography */
h1 {
    font-size: 2.5rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

h2 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.description {
    font-size: 1.125rem;
    color: var(--text-secondary);
    max-width: 540px;
    margin: 0 auto;
}

.description strong {
    color: var(--purple-primary);
    font-weight: 600;
}

/* Buttons */
.primary-button,
.secondary-button {
    font-size: 1rem;
    font-weight: 500;
    padding: 0.875rem 2rem;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 180px;
}

.primary-button {
    background-color: var(--purple-primary);
    color: white;
}

.primary-button:hover:not(:disabled) {
    background-color: var(--purple-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(109, 74, 255, 0.3);
}

.primary-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.secondary-button {
    background-color: transparent;
    color: var(--purple-primary);
    border: 2px solid var(--purple-primary);
}

.secondary-button:hover:not(:disabled) {
    background-color: var(--purple-light);
}

.secondary-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.text-link {
    font-size: 0.9375rem;
    color: var(--purple-primary);
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem 1rem;
    text-decoration: underline;
    transition: color 0.2s ease;
    margin-top: 1rem;
}

.text-link:hover {
    color: var(--purple-hover);
}

/* Progress Bar */
.test-header {
    width: 100%;
    max-width: 400px;
}

.progress-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.progress-bar {
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--purple-primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

#question-counter {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Word Display */
.word-display {
    font-size: 4rem;
    font-weight: 700;
    padding: 2.5rem 3rem;
    background-color: var(--word-display-bg);
    border: 2px solid var(--word-display-border);
    border-radius: 12px;
    min-width: 320px;
    margin: 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    user-select: none;
}

/* Feedback */
.feedback {
    padding: 1rem 1.5rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 1.125rem;
    min-height: 3.5rem;
}

.feedback.error {
    background-color: rgba(224, 24, 77, 0.1);
    color: var(--error);
    border: 2px solid var(--error);
}

.feedback.success {
    background-color: rgba(0, 179, 77, 0.1);
    color: var(--success);
    border: 2px solid var(--success);
}

/* Answer Section */
.answer-section {
    width: 100%;
    max-width: 600px;
}

.options-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.option-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    min-height: 60px;
    background-color: var(--surface-bg);
    font-size: 1rem;
    gap: 0.5rem;
    line-height: 1.2;
}

.option-label:hover {
    border-color: var(--purple-primary);
    background-color: var(--purple-light);
    transform: translateY(-1px);
}

.option-label.selected {
    border-color: var(--purple-primary);
    background-color: var(--purple-light);
}

.option-label input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Number prefix styling (inline instead of badge) */
.option-number {
    font-size: 0.875rem;
    color: var(--purple-primary);
    font-weight: 600;
    flex-shrink: 0;
}

.option-text {
    flex: 1;
    text-align: center;
    word-break: normal;
}

/* Results Screen */
.celebration {
    animation: bounceIn 0.6s ease-out;
    margin-bottom: 1rem;
}

@keyframes bounceIn {
    0%, 20%, 40%, 60%, 80%, 100% {
        animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
    }
    0% {
        opacity: 0;
        transform: scale3d(0.3, 0.3, 0.3);
    }
    20% {
        transform: scale3d(1.1, 1.1, 1.1);
    }
    40% {
        transform: scale3d(0.9, 0.9, 0.9);
    }
    60% {
        opacity: 1;
        transform: scale3d(1.03, 1.03, 1.03);
    }
    80% {
        transform: scale3d(0.97, 0.97, 0.97);
    }
    100% {
        opacity: 1;
        transform: scale3d(1, 1, 1);
    }
}

.results-info {
    display: flex;
    gap: 2rem;
    justify-content: center;
    flex-wrap: wrap;
    margin: 1.5rem 0;
}

.result-card {
    background-color: var(--purple-light);
    padding: 1.5rem 2rem;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 150px;
}

.result-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.result-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--purple-primary);
}

.time-message {
    font-size: 1.125rem;
    color: var(--text-secondary);
    margin: 1rem 0;
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        padding: 2rem 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    .word-display {
        font-size: 2.5rem;
        padding: 1.5rem 1rem;
        min-width: 240px;
    }

    .options-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .option-label {
        padding: 0.875rem;
        font-size: 0.9375rem;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}