:root {
    /* Color Palette */
    --bg-color: #1e1b4b; /* Deep Indigo */
    --text-main: #ffffff;
    --text-muted: #cbd5e1;
    
    /* Brand Colors */
    --primary: #8b5cf6; /* Violet */
    --primary-shadow: #5b21b6;
    
    --secondary: #ec4899; /* Pink */
    --secondary-shadow: #be185d;

    --success: #10b981; /* Emerald */
    --success-shadow: #047857;

    --danger: #f43f5e; /* Rose */
    --danger-shadow: #be123c;

    --btn-bg: #334155; /* Slate */
    --btn-shadow: #0f172a;
    
    --card-bg: #ffffff;
    --card-text: #0f172a;
}

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

body {
    font-family: 'Nunito', sans-serif;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #1e1b4b 100%);
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    transition: background 0.5s ease;
}

/* Background Themes */
body.theme-flashcard { background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); }
body.theme-quiz { background: linear-gradient(135deg, #310e68 0%, #5b21b6 100%); }
body.theme-memory { background: linear-gradient(135deg, #064e3b 0%, #0f766e 100%); }
body.theme-truefalse { background: linear-gradient(135deg, #7f1d1d 0%, #9f1239 100%); }

body.theme-flashcard .app-container,
body.theme-quiz .app-container,
body.theme-memory .app-container,
body.theme-truefalse .app-container {
    max-width: 100%;
    min-height: 100vh;
    margin: 0;
    border-radius: 0;
    border: none;
    box-shadow: none;
}

@keyframes gradientBG {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Background floating elements (pseudo) */
body::before, body::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    z-index: -1;
    animation: float 10s infinite ease-in-out alternate;
}

body::before {
    width: 300px;
    height: 300px;
    background: rgba(139, 92, 246, 0.4);
    top: -50px;
    left: -50px;
}

body::after {
    width: 400px;
    height: 400px;
    background: rgba(236, 72, 153, 0.3);
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(30px, 50px) scale(1.1); }
}

.app-container {
    width: 100%;
    max-width: 500px;
    min-height: 85vh;
    margin: 20px;
    padding: 30px;
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-radius: 32px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#main-content {
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 30px;
}

.logo {
    font-size: 2.8rem;
    font-weight: 900;
    letter-spacing: -1px;
    margin-bottom: 5px;
    text-shadow: 2px 4px 0px rgba(0,0,0,0.3);
}

.logo span {
    color: var(--secondary);
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    font-weight: 600;
}

/* Views */
.view {
    display: none;
    animation: bounceIn 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
    flex-direction: column;
    flex: 1;
}

.view.active-view {
    display: flex;
}

@keyframes bounceIn {
    0% { opacity: 0; transform: scale(0.9) translateY(20px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    text-align: center;
    font-weight: 800;
    text-shadow: 1px 2px 0px rgba(0,0,0,0.2);
}

/* Gamified Buttons */
.grid-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.mode-grid {
    flex-direction: row;
    gap: 16px;
}

.glass-btn {
    background: var(--btn-bg);
    border: none;
    border-radius: 20px;
    padding: 16px 24px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    width: 100%;
    /* 3D effect */
    box-shadow: 0 6px 0 var(--btn-shadow);
    transform: translateY(0);
}

.glass-btn:active {
    box-shadow: 0 0px 0 var(--btn-shadow);
    transform: translateY(6px);
}

.glass-btn.primary {
    background: var(--primary);
    box-shadow: 0 6px 0 var(--primary-shadow);
}
.glass-btn.primary:active {
    box-shadow: 0 0 0 var(--primary-shadow);
    transform: translateY(6px);
}

.level-btn {
    justify-content: flex-start;
}

.level-badge {
    background: var(--secondary);
    padding: 6px 14px;
    border-radius: 12px;
    font-weight: 900;
    font-size: 1rem;
    box-shadow: 0 3px 0 var(--secondary-shadow);
    color: #fff;
}

.mode-btn {
    flex: 1;
    flex-direction: column;
    padding: 25px 15px;
    text-align: center;
    gap: 8px;
}

.mode-icon {
    font-size: 3.5rem;
    margin-bottom: 5px;
    filter: drop-shadow(0 4px 0 rgba(0,0,0,0.2));
}

.mode-btn h3 {
    font-size: 1.4rem;
}

.mode-btn p {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
}

.back-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
    margin-bottom: 20px;
    display: inline-block;
    transition: transform 0.2s;
}

.back-btn:hover {
    color: var(--text-main);
    transform: translateX(-5px);
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 15px;
    flex-wrap: wrap;
}

.top-bar .back-btn {
    margin-bottom: 0;
}

.quiz-stats {
    display: flex;
    gap: 10px;
    align-items: center;
}

.counter, .score {
    background: rgba(0,0,0,0.4);
    padding: 8px 16px;
    border-radius: 16px;
    font-size: 1rem;
    font-weight: 800;
    color: var(--text-main);
    border: 2px solid rgba(255,255,255,0.1);
    white-space: nowrap;
}

.fc-stats {
    display: flex;
    gap: 10px;
    align-items: center;
}

.icon-btn {
    padding: 8px 15px;
    border-radius: 12px;
    font-size: 1.2rem;
    background: var(--btn-bg);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--btn-shadow);
    transition: transform 0.1s;
}

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

/* Flashcard Speak Button - Fixed below cards */
.fc-controls {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    margin-bottom: auto;
}

.speak-card-btn {
    border-radius: 50%;
    width: 65px;
    height: 65px;
    font-size: 1.8rem;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--success);
    color: white;
    border: none;
    box-shadow: 0 6px 0 var(--success-shadow);
    transition: all 0.1s;
    cursor: pointer;
}

.speak-card-btn:active {
    box-shadow: 0 0 0 var(--success-shadow);
    transform: translateY(6px);
}

/* Flashcard Swipe & 3D look */
.swipe-container {
    height: 60vh;
    overflow-y: auto;
    scroll-snap-type: y mandatory;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 20px;
    scrollbar-width: none; /* Firefox */
    margin-top: auto;
    margin-bottom: auto;
}

.swipe-container::-webkit-scrollbar {
    display: none; /* Safari/Chrome */
}

.swipe-card {
    width: 100%;
    height: 100%;
    flex-shrink: 0;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Flashcard 3D physical look */
.flashcard-container {
    perspective: 1200px;
    width: 100%;
    height: 350px;
}

.flashcard {
    width: 100%;
    height: 100%;
    cursor: pointer;
    position: relative;
}

.flashcard-inner {
    width: 100%;
    height: 100%;
    position: absolute;
    transition: transform 0.9s cubic-bezier(0.34, 1.56, 0.64, 1); /* Smoother, slower bouncy flip */
    transform-style: preserve-3d;
    will-change: transform; /* Hardware acceleration for 60fps */
}

.flashcard.is-flipped .flashcard-inner {
    transform: rotateY(180deg);
}

.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: var(--card-bg);
    color: var(--card-text);
    border-radius: 28px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    /* Thick physical card look */
    border: 4px solid #e2e8f0;
    box-shadow: 0 10px 20px rgba(0,0,0,0.3), inset 0 -4px 0 #cbd5e1;
}

.flashcard-back {
    transform: rotateY(180deg);
    background: #f8fafc;
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0,0,0,0.3), inset 0 -4px 0 var(--primary-shadow);
}

.flashcard h2 {
    font-size: 3.5rem;
    margin-bottom: 5px;
    color: var(--card-text);
    text-shadow: none;
}

.flashcard .hint {
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.9rem;
    font-weight: 800;
}



/* Quiz */
.quiz-container {
    text-align: center;
    margin-top: auto;
    margin-bottom: auto;
}

.question {
    font-size: 3rem;
    margin-bottom: 5px;
    font-weight: 900;
    text-shadow: 2px 2px 0px rgba(0,0,0,0.3);
}

.question-subtitle {
    color: var(--text-muted);
    margin-bottom: 30px;
    font-weight: 600;
}

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.option-btn {
    padding: 24px 10px;
    font-size: 1.2rem;
}

/* Correct Answer Animation */
.option-btn.correct {
    background: var(--success) !important;
    box-shadow: 0 6px 0 var(--success-shadow) !important;
    animation: pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Wrong Answer Animation */
.option-btn.wrong {
    background: var(--danger) !important;
    box-shadow: 0 6px 0 var(--danger-shadow) !important;
    animation: shake 0.4s ease-in-out;
}

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

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

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

/* Results Overlay */
.results-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 28px;
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.results-overlay.hidden {
    display: none;
}

.glass-panel {
    background: rgba(255,255,255,0.1);
    padding: 40px 30px;
    border-radius: 28px;
    border: 2px solid rgba(255,255,255,0.2);
    text-align: center;
    width: 85%;
    box-shadow: 0 20px 40px rgba(0,0,0,0.4);
    animation: pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.glass-panel p {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-muted);
}

.final-score {
    font-size: 4.5rem;
    font-weight: 900;
    color: #fcd34d;
    text-shadow: 0 4px 0 #d97706, 0 10px 20px rgba(0,0,0,0.5);
    margin: 15px 0;
}

.mt-2 { margin-top: 12px; }
.mt-4 { margin-top: 24px; }

/* Responsive */
@media (max-width: 480px) {
    .mode-grid {
        flex-direction: column;
    }
    .options-grid {
        grid-template-columns: 1fr;
    }
    .flashcard h2 {
        font-size: 2.8rem;
    }
    .question {
        font-size: 2.2rem;
    }
}

/* Memory Match Mode */
.memory-split-container {
    display: flex;
    justify-content: space-between;
    gap: 40px; /* Increased gap */
    margin-top: auto;
    margin-bottom: auto;
    height: 60vh;
}

.memory-column-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.memory-col-title {
    text-align: center;
    margin-bottom: 12px;
    font-size: 1.4rem;
    font-weight: 900;
    color: #ffeb3b;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.memory-column {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 columns x 3 rows = 6 cards */
    gap: 12px;
    align-content: start;
}

.memory-card {
    background: var(--card-bg);
    color: var(--card-text);
    border: 3px solid #e2e8f0;
    border-radius: 12px;
    height: 65px; /* Perfect height for 6 rows in fullscreen */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem; 
    font-weight: 800;
    cursor: pointer;
    text-align: center;
    padding: 0 10px;
    box-shadow: 0 6px 0 #cbd5e1;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    user-select: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.memory-card:active {
    box-shadow: 0 0 0 #cbd5e1;
    transform: translateY(6px);
}

.memory-card.flipped {
    background: var(--primary);
    color: white;
    border-color: var(--primary-shadow);
    box-shadow: 0 6px 0 var(--primary-shadow);
    transform: scale(1.05);
}
.memory-card.flipped:active {
    box-shadow: 0 0 0 var(--primary-shadow);
    transform: scale(1.05) translateY(6px);
}

.memory-card.matched {
    background: var(--success);
    color: white;
    border-color: var(--success-shadow);
    box-shadow: 0 6px 0 var(--success-shadow);
    animation: popOut 0.5s forwards;
    pointer-events: none;
}

@keyframes popOut {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(0); opacity: 0; }
}

/* True/False Mode */
.tf-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
    margin-top: auto;
    margin-bottom: auto;
}
.tf-card {
    padding: 50px 20px;
    animation: bounceIn 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
.tf-buttons {
    display: flex;
    gap: 15px;
}
.tf-btn {
    flex: 1;
    padding: 30px 10px;
    font-size: 1.4rem;
}
