:root {
    --primary-color: #FF5E5B;
    /* Vibrant Red/Pink */
    --secondary-color: #FFD400;
    /* Bright Yellow */
    --tertiary-color: #00CECB;
    /* Teal/Cyan */
    --bg-color: #2F2F2F;
    /* Dark Gray Background */
    --text-color: #FFFFFF;
    --card-bg: #404040;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', 'Fredoka', sans-serif;
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 10% 10%, #3a3a3a 0%, #2f2f2f 100%);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    text-align: center;
    width: 95%;
    max-width: 1000px;
}

.main-header {
    background: rgba(64, 64, 64, 0.4);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 2.5rem 2rem;
    border-radius: 24px;
    margin-bottom: 2.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.title {
    font-family: 'Outfit', sans-serif;
    font-weight: 900;
    font-size: 5rem;
    margin-bottom: 0.5rem;
    letter-spacing: -2px;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 5px 15px rgba(255, 94, 91, 0.3));
    animation: float 4s infinite ease-in-out;
}

.title .highlight {
    background: linear-gradient(135deg, var(--tertiary-color), #4facfe);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.title .polyglot {
    background: linear-gradient(135deg, #a18cd1, #fbc2eb);
    /* Purple to Pink */
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 5px 15px rgba(161, 140, 209, 0.3));
}

.subtitle {
    font-size: 1.3rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 0;
    letter-spacing: 1px;
    text-transform: uppercase;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.card {
    background-color: var(--card-bg);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    border: 4px solid var(--tertiary-color);
    transition: transform 0.2s;
}

.card:hover {
    transform: scale(1.02);
}

.sentence-box {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 0.8rem;
    min-height: 60px;
    display: flex;
    flex-direction: row;
    /* Horizontal */
    flex-wrap: wrap;
    /* Wrap if too long */
    gap: 1rem;
    /* Distinct space between words */
    align-items: center;
    justify-content: center;
    color: var(--text-color);
    line-height: 1.2;
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
    width: 100%;
}



.buttons-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.btn {
    font-family: 'Fredoka', sans-serif;
    font-size: 1.2rem;
    padding: 1rem 2rem;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
    text-transform: uppercase;
    box-shadow: 0 5px 0 rgba(0, 0, 0, 0.2);
}

.btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.primary-btn {
    background-color: var(--primary-color);
    color: white;
}

.primary-btn:hover {
    background-color: #ff3b38;
}

.secondary-btn {
    background-color: var(--tertiary-color);
    color: #2F2F2F;
}

.secondary-btn:hover {
    background-color: #00b3b0;
}

.explanation {
    margin-top: 2rem;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: nowrap;
    /* Keep them in one row! */
    width: 100%;
}

.word-tag {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 0.8rem 1.2rem;
    border-radius: 12px;
    font-size: 1.1rem;
}

.lang-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    opacity: 0.7;
    display: block;
    margin-bottom: 0.2rem;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

/* Colors for specific languages in the breakdown */
.lang-en {
    color: #81c784;
}

/* Greenish for English */
.lang-ms {
    color: #ffd54f;
}

/* Yellowish for Malay */
.lang-ar {
    color: #64b5f6;
}

/* Blueish for Arabic */

/* Language Selector Styles */
.language-selector-container {
    margin-bottom: 2rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 1.5rem;
    border-radius: 15px;
    border: 2px solid rgba(255, 255, 255, 0.1);
}

.language-selector-container h3 {
    color: var(--secondary-color);
    font-size: 1.3rem;
    margin-bottom: 1rem;
    text-align: center;
}

.language-checkboxes {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.language-checkbox {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.2rem;
    border: 3px solid;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: rgba(0, 0, 0, 0.2);
    font-weight: 600;
    font-size: 1rem;
}

.language-checkbox:hover {
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.1);
}

.language-checkbox input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    cursor: pointer;
}

.checkmark {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.language-checkbox input[type="checkbox"]:checked~.checkmark {
    opacity: 1;
}

.language-checkbox input[type="checkbox"]:checked~.checkmark::after {
    content: "✓";
    color: white;
    font-weight: bold;
    font-size: 14px;
}

.language-checkbox input[type="checkbox"]:not(:checked)~.checkmark {
    opacity: 0.3;
}

/* Orange for Chinese */
.lang-zh {
    color: #ff8a65;
}

/* Purple for Russian */
.lang-ru {
    color: #ba68c8;
}

/* Pink for Japanese */
.lang-ja {
    color: #ff6b9d;
}

/* Purple for Korean */
.lang-ko {
    color: #9575cd;
}

/* Romanization styling */
.romanization {
    font-size: 0.75em;
    color: #ffeb3b;
    font-style: italic;
    margin-top: 0.2rem;
    opacity: 0.9;
}

/* 3-Row Breakdown Arrangement */
.translation-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 10px;
    text-align: left;
    width: 100%;
}

.translation-row {
    font-size: 1.1em;
    color: #ccc;
    display: flex;
    align-items: baseline;
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    gap: 0;
}

.active-lang {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-left: 3px solid #ffeb3b;
}

.row-label {
    font-weight: bold;
    min-width: 30px;
    font-size: 0.9em;
    opacity: 0.7;
    margin-right: 8px;
    flex-shrink: 0;
}

.row-text {
    flex-shrink: 1;
    flex-grow: 0;
}

.row-rom {
    font-size: 1.0em;
    color: #ffeb3b;
    margin-left: 8px;
    font-style: italic;
}

.main-word {
    font-size: 1.6em;
    margin-bottom: 5px;
}

.word-tag {
    flex: 1;
    /* Allow them to share space equally */
    min-width: 300px;
    /* Increased slightly for larger text */
    max-width: 350px;
}

@media (max-width: 600px) {
    .title {
        font-size: 3rem;
        letter-spacing: -1px;
    }

    .subtitle {
        font-size: 1rem;
    }

    .main-header {
        padding: 1.5rem 1rem;
    }

    .explanation {
        flex-wrap: wrap;
        /* Allow stacking on mobile! */
        padding: 0 10px;
    }

    .word-tag {
        min-width: 100%;
        max-width: 100%;
    }
}

/* Quiz Mode Styles */
.hidden-sentence {
    filter: blur(8px);
    transition: filter 0.5s ease;
    user-select: none;
    pointer-events: none;
}

.hidden-sentence span {
    color: transparent !important;
    text-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.quiz-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin: 20px 0;
    width: 100%;
    transition: all 0.3s ease;
}

.quiz-container.hidden {
    display: none;
}

.quiz-opt {
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    color: white;
    font-size: 1.1em;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    backdrop-filter: blur(5px);
    font-family: 'Outfit', sans-serif;
}

.quiz-opt:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.3);
}

.quiz-opt.correct {
    background: rgba(76, 175, 80, 0.3) !important;
    border-color: #4caf50 !important;
    box-shadow: 0 0 15px rgba(76, 175, 80, 0.4);
}

.quiz-opt.incorrect {
    background: rgba(244, 67, 54, 0.3) !important;
    border-color: #f44336 !important;
    animation: shake 0.4s ease-in-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

/* Switch Styles */
.mode-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 0px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 20px;
    border-radius: 50px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Quiz Stats Styles */
.quiz-stats {
    display: flex;
    align-items: stretch;
    justify-content: center;
    gap: 20px;
    margin-top: 0px;
    margin-bottom: 0px;
    transition: all 0.3s ease;
}

.quiz-stats.hidden {
    display: none;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(135deg, rgba(0, 206, 203, 0.25), rgba(100, 181, 246, 0.25));
    padding: 12px 20px;
    border-radius: 15px;
    border: 2px solid var(--tertiary-color);
    backdrop-filter: blur(15px);
    box-shadow: 0 6px 24px rgba(0, 206, 203, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-width: 140px;
}

.stat-item::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg,
            transparent,
            rgba(255, 255, 255, 0.1),
            transparent);
    transform: rotate(45deg);
    animation: shimmer 3s infinite;
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%) translateY(-100%) rotate(45deg);
    }

    100% {
        transform: translateX(100%) translateY(100%) rotate(45deg);
    }
}

.stat-item:hover {
    transform: translateY(-5px) scale(1.05);
    box-shadow: 0 12px 40px rgba(0, 206, 203, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.3);
    border-color: #00fffc;
}

.stat-label {
    font-weight: 700;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-value {
    font-weight: 900;
    font-size: 1.8rem;
    color: var(--secondary-color);
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 12px;
    border: 2px solid rgba(255, 212, 0, 0.6);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5),
        0 0 15px rgba(255, 212, 0, 0.3);
    transition: all 0.3s ease;
    min-width: 85px;
    text-shadow: 0 0 10px rgba(255, 212, 0, 0.5),
        0 2px 4px rgba(0, 0, 0, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }
}

.stat-value:hover {
    transform: scale(1.08);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5),
        0 0 20px rgba(255, 212, 0, 0.6);
    border-color: var(--secondary-color);
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .quiz-stats {
        flex-direction: row;
        gap: 10px;
        margin-top: 0;
        margin-bottom: 0;
    }

    .stat-item {
        min-width: auto;
        flex: 1;
        padding: 8px 12px;
        gap: 4px;
    }

    .stat-label {
        font-size: 0.65rem;
        letter-spacing: 1px;
    }

    .stat-value {
        font-size: 1.3rem;
        padding: 6px 10px;
        min-width: 60px;
    }
}

/* Arabic and special script enhancement in quiz options */
.quiz-opt {
    font-size: 1.4rem;
    line-height: 1.5;
}

.mode-label {
    font-weight: 600;
    font-size: 0.9em;
    color: var(--text-color);
}

.switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 24px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 2px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--primary-color);
}

input:checked+.slider:before {
    transform: translateX(26px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

@media (max-width: 600px) {
    .quiz-container {
        grid-template-columns: 1fr;
    }
}

/* Voice Settings Modal */
.settings-btn {
    background-color: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 1rem 1.2rem;
    font-size: 1.5rem;
}

.settings-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: rotate(45deg);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--card-bg);
    border: 2px solid var(--tertiary-color);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    animation: bounce 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--secondary-color);
    font-family: 'Outfit', sans-serif;
}

.close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.voice-list {
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.voice-group {
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 12px;
}

.voice-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--tertiary-color);
    font-weight: bold;
    font-size: 0.9rem;
    text-transform: uppercase;
}

.voice-select {
    width: 100%;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    cursor: pointer;
}

.voice-select:focus {
    border-color: var(--secondary-color);
    outline: none;
}

.voice-select option {
    background: #333;
}

/* Voice Help Text */
.voice-help {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(255, 235, 59, 0.1);
    border: 1px solid rgba(255, 235, 59, 0.3);
    border-radius: 8px;
    color: #ccc;
    font-size: 0.9em;
    text-align: center;
}

.voice-help strong {
    color: #ffeb3b;
    display: block;
    margin-bottom: 0.5rem;
}

.voice-help small {
    display: block;
    line-height: 1.6;
    color: #aaa;
}