/* CSS reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    text-size-adjust: none;
}

body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: opacity 0.5s ease-in-out;
}

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
}

input, button, textarea, select {
    font: inherit;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 650;
    text-wrap: balance;
    overflow-wrap: break-word;
}

/* Custom styles */
html {
    font-family: "Comic Neue", "Open Sans", sans-serif;
    font-size: clamp(16px, 0.8vw + 12px, 18px);
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    overflow: hidden;
}

body {
    display: contents;
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.9;
    transition: opacity 0.5s ease-in-out;
}

body.easy::before {
    background-image: url('https://images.unsplash.com/photo-1507525428034-b723cf961d3e?ixlib=rb-4.0.3&auto=format&fit=crop&w=1920&q=80'); /* Sunny meadow */
}

body.medium::before {
    background-image: url('https://images.unsplash.com/photo-1541959833400-049d37f98ccd?q=80&w=2940&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); /* Jungle */
}

body.hard::before {
    background-image: url('https://images.unsplash.com/photo-1606247357835-d27fe83fc6a3?q=80&w=2938&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); /* Starry night */
}

main {
    padding: 0.8rem;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    row-gap: 0.5rem;
    max-width: 65rem;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(5px);
}

.container {
    max-width: 600px;
    width: 100%;
    padding: 10px;
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(5px);
}

#header {
    color: #002b5c;
    line-height: 1.2;
    font-size: 2rem;
    margin-bottom: 0.1rem;
    grid-row: 1 / 2;
}

#entries {
    display: none;
}

#progress-container {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    margin-top: 0.2rem;
    grid-row: 2 / 3;
}

#progress-bar {
    width: 100%;
    height: 10px;
    background-color: #e0e0e0; /* Solid light gray background */
    border-radius: 8px;
    overflow: hidden;
    transition: box-shadow 0.3s ease, transform 0.3s ease;
}

#progress-bar:hover {
    box-shadow: 0 0 10px rgba(0, 122, 204, 0.5);
    transform: scale(1.02);
}

#progress-bar-inner {
    width: 0%;
    height: 100%;
    background-color: #4caf50; /* Solid green fill */
    border-radius: 8px;
    transition: width 0.5s ease-in-out;
}

/* Ensure no theme-specific overrides for progress bar */
body.easy #progress-bar,
body.medium #progress-bar,
body.hard #progress-bar {
    background-color: #e0e0e0;
}

body.easy #progress-bar-inner,
body.medium #progress-bar-inner,
body.hard #progress-bar-inner {
    background-color: #4caf50;
}

#progress-text {
    text-align: center;
    font-size: 2rem;
    color: #007acc;
    background-color: #fff9e6; /* Solid pale yellow background */
    border: 1px solid #ffca28;
    border-radius: 5px;
    padding: 0.3rem 0.8rem;
    margin: 0;
    font-weight: bold;
    min-height: 2.5rem;
    z-index: 10;
    position: relative;
}

/* Ensure no theme-specific overrides for progress text */
body.easy #progress-text,
body.medium #progress-text,
body.hard #progress-text {
    background-color: #fff9e6;
}

#progress-text.pulse {
    animation: pulseProgress 0.3s ease-in-out;
}

#flashcard {
    grid-row: 3 / 4;
    height: auto;
    max-height: calc(100% - 2rem);
    position: relative;
    perspective: 80rem;
    z-index: 1;
    margin-bottom: 0;
}

#card-inner {
    position: absolute;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2;
}

#flip-card-checkbox:checked ~ * #card-inner,
#flip-card-checkbox:checked + #flashcard #card-inner,
#card-inner.flipped {
    transform: rotateY(180deg);
}

.card {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background-color: #fff9e6;
    border: 2px solid #ffca28;
    font-size: 1.6rem;
    border-radius: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: box-shadow 0.3s;
    z-index: 3;
}

.card:hover {
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.card-front {
    color: #1a3c5e;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.8rem;
}

.question-container {
    display: flex !important;
    flex-direction: column;
    gap: 0.8rem;
    text-align: center;
}

#text {
    display: block !important;
    font-size: 2.2rem;
    font-weight: 700;
}

#question-text {
    display: block !important;
    font-size: 1.4rem;
    color: #1a3c5e;
}

.card-back {
    transform: rotateY(180deg);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;
}

#correctness {
    font-size: 1.8rem;
    font-weight: 700;
    color: #d81b60;
}

#explanation {
    font-size: 1.4rem;
    color: #555;
}

.card-buttons {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

#option-1,
#option-2,
#option-3,
#submit-answer,
#btn-reset,
#btn-hint,
#btn-audio,
#btn-audio-back {
    appearance: none;
    display: block !important;
    border: 2px solid #ffca28;
    padding: 0.6rem 1.8rem;
    font-size: 1rem;
    border-radius: 1rem;
    background: #ffeb3b;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s, box-shadow 0.3s, transform 0.2s;
    cursor: pointer;
    color: #1a3c5e;
    margin: 0.3rem;
}

#btn-hint,
#btn-audio,
#btn-audio-back {
    background-color: #90caf9;
    border-color: #64b5f6;
}

#option-1:hover,
#option-2:hover,
#option-3:hover,
#submit-answer:hover,
#btn-reset:hover,
#btn-hint:hover,
#btn-audio:hover,
#btn-audio-back:hover {
    background-color: #ffd700;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-3px);
}

#btn-hint:hover,
#btn-audio:hover,
#btn-audio-back:hover {
    background-color: #64b5f6;
}

#option-1:disabled,
#option-2:disabled,
#option-3:disabled,
#submit-answer:disabled,
#btn-reset:disabled,
#btn-hint:disabled,
#btn-audio:disabled,
#btn-audio-back:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

#hint-text {
    font-size: 1.2rem;
    color: #007acc;
    margin: 0.5rem;
    text-align: center;
}

#actions {
    grid-row: 4 / 5;
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-top: 0;
    min-height: 3rem;
    z-index: 5;
}

button {
    appearance: none;
    border: 2px solid #ffca28;
    padding: 0.7rem 2.2rem;
    font-size: 1rem;
    border-radius: 1rem;
    background-color: #ffeb3b;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
    transition: background-color 0.3s, box-shadow 0.3s, transform 0.2s;
    cursor: pointer;
    color: #1a3c5e;
    display: block;
}

button:hover {
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    background-color: #ffd700;
    transform: translateY(-3px);
}

#btn-next-question,
#btn-try-again,
#btn-home {
    background-color: #90caf9;
    border-color: #64b5f6;
    font-size: 1rem;
    padding: 0.7rem 2.2rem;
    z-index: 5;
}

#btn-next-question:hover,
#btn-try-again:hover,
#btn-home:hover {
    background-color: #64b5f6;
}

#btn-next-question,
#btn-try-again {
    display: none;
}

#btn-next-question.active,
#btn-try-again.active {
    display: block !important;
}

h1 {
    font-size: 36px;
    color: #007acc;
    margin-bottom: 10px;
    animation: pulse 1s ease-in-out;
}

.welcome-text {
    font-size: 22px;
    color: #333;
    margin: 15px 0;
    animation: fadeIn 1s ease-in;
}

.button-group {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 15px;
}

.btn {
    font-family: "Comic Neue", sans-serif;
    font-size: 18px;
    padding: 12px 24px;
    background-color: #007acc;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s;
}

.btn:hover {
    background-color: #005f99;
    transform: scale(1.05);
}

.btn:active {
    transform: scale(0.95);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.difficulty-group .btn {
    width: 140px;
    text-align: center;
    font-size: 1.2rem;
    padding: 12px;
}

#btn-easy {
    background-color: #4caf50;
    border: none;
}
#btn-easy:hover {
    background-color: #388e3c;
}
#btn-medium {
    background-color: #f59e0b;
    border: none;
}
#btn-medium:hover {
    background-color: #d97706;
}
#btn-hard {
    background-color: #ef4444;
    border: none;
}
#btn-hard:hover {
    background-color: #dc2626;
}

.results-text {
    font-size: 24px;
    font-weight: bold;
    color: #333;
    margin: 15px 0;
}

.stars-container {
    font-size: 30px;
    margin: 8px 0;
    color: #ffca28;
    animation: twinkle 2s infinite;
}

.message-text {
    font-size: 20px;
    color: #007acc;
    margin: 12px 0;
}

.incorrect-list {
    font-size: 18px;
    color: #d81b60;
    margin: 15px 0;
}

.sentence-words {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.8rem 0;
    justify-content: center;
}

.sentence-word {
    padding: 0.6rem 1.2rem;
    border: 2px solid #ffca28;
    border-radius: 8px;
    background-color: #bbdefb;
    cursor: pointer;
    font-size: 1.2rem;
    color: #1a3c5e;
    transition: background-color 0.2s, transform 0.2s;
}

.sentence-word:hover {
    background-color: #90caf9;
    transform: scale(1.05);
}

.sentence-builder-area {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.8rem 0;
    padding: 0.5rem;
    background-color: rgba(255, 202, 40, 0.1);
    border: 2px dashed #ffca28;
    min-height: 3rem;
    justify-content: center;
}

.sentence-builder-word {
    padding: 0.6rem 1.2rem;
    border: 2px solid #ffca28;
    border-radius: 8px;
    background-color: #90caf9;
    cursor: pointer;
    font-size: 1.2rem;
    color: #1a3c5e;
    transition: background-color 0.2s, transform 0.2s;
}

.sentence-builder-word:hover {
    background-color: #64b5f6;
    transform: scale(1.05);
}

@keyframes twinkle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

@keyframes pulseProgress {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

@keyframes fadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

#text.error,
#question-text.error {
    color: #d81b60;
    font-weight: bold;
}

@media (max-width: 360px) {
    #header {
        font-size: 1.8rem;
    }
    #progress-text {
        font-size: 1.6rem;
        padding: 0.2rem 0.6rem;
    }
    #progress-bar {
        height: 8px;
    }
    #progress-bar:hover {
        transform: scale(1.01);
    }
    #progress-text.pulse {
        animation: pulseProgress 0.4s ease-in-out;
    }
    .card {
        padding: 1.2rem;
        font-size: 1.4rem;
    }
    #question-text {
        font-size: 1.2rem;
    }
    #text {
        font-size: 2.2rem;
    }
    #correctness {
        font-size: 1.6rem;
    }
    #explanation {
        font-size: 1.2rem;
    }
    #option-1,
    #option-2,
    #option-3,
    #submit-answer,
    #btn-reset,
    #btn-hint,
    #btn-audio,
    #btn-audio-back {
        padding: 0.5rem 1.4rem;
        font-size: 0.9rem;
        margin: 0.2rem;
    }
    #btn-next-question,
    #btn-try-again,
    #btn-home {
        padding: 0.6rem 2rem;
        font-size: 0.9rem;
    }
    .sentence-word,
    .sentence-builder-word {
        padding: 0.5rem 1rem;
        font-size: 1rem;
    }
    .btn {
        font-size: 16px;
        padding: 10px 20px;
    }
    .difficulty-group .btn {
        width: 120px;
        font-size: 1rem;
        padding: 10px;
    }
    body::before {
        background-size: contain;
        background-position: top center;
    }
}