:root {
    --primary-color: #6d8aff;
    --primary-hover: #5572ee;
    --bg-color: #f0f4f8;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
    --success: #10b981;
    --error: #ef4444;
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

/* Background Blobs for Aesthetics */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.6;
}

.blob-1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: #ffc4e1;
    animation: float 15s ease-in-out infinite alternate;
}

.blob-2 {
    bottom: -10%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: #cbf0ff;
    animation: float 12s ease-in-out infinite alternate-reverse;
}

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

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Glassmorphism Classes */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 20px;
}

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

.header h1 {
    font-size: 2.2rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: var(--primary-color);
}

.category-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 15px;
    margin-bottom: 20px;
}

.cat-btn {
    padding: 10px 20px;
    border-radius: 30px;
    border: none;
    background: rgba(255,255,255,0.5);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: inherit;
}

.cat-btn:hover {
    background: rgba(255,255,255,0.9);
    transform: translateY(-2px);
}

.cat-btn.active {
    background: var(--primary-color);
    color: white;
    box-shadow: 0 4px 15px rgba(109, 138, 255, 0.4);
}

.mode-switch {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.mode-btn {
    padding: 10px 25px;
    border: 2px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    font-size: 1rem;
}

.mode-btn:hover {
    background: rgba(109, 138, 255, 0.1);
}

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

.progress-container {
    max-width: 500px;
    margin: 0 auto;
}

.progress-text {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
}

.progress-bar-bg {
    height: 10px;
    background: rgba(0,0,0,0.05);
    border-radius: 5px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color), var(--success));
    transition: width 0.5s ease;
}

.audio-settings-bar {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
    font-size: 0.95rem;
    font-weight: 600;
}

.audio-settings-bar select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(0,0,0,0.1);
    background: rgba(255,255,255,0.8);
    font-family: inherit;
    font-size: 0.9rem;
    color: var(--text-main);
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
}

.audio-settings-bar select:hover {
    border-color: var(--primary-color);
}

.filter-box select {
    padding: 12px 15px;
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 25px;
    font-size: 1rem;
    outline: none;
    background: rgba(255,255,255,0.8);
    transition: all 0.3s;
    font-family: inherit;
    cursor: pointer;
}

.filter-box select:focus {
    border-color: var(--primary-color);
}
.controls {
    padding: 15px 25px;
    margin-bottom: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.search-box {
    display: flex;
    align-items: center;
    background: white;
    padding: 10px 15px;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    border: 1px solid rgba(0,0,0,0.05);
}

.search-box i {
    color: var(--text-muted);
    margin-right: 10px;
}

.search-box input {
    border: none;
    outline: none;
    background: transparent;
    width: 100%;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-main);
}

/* Flashcards Grid */
.flashcards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 25px;
}

/* Single Flashcard (3D Flip Effect) */
.card-scene {
    perspective: 1000px;
    height: 250px;
}

.flashcard {
    width: 100%;
    height: 100%;
    position: relative;
    transition: transform 0.6s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
    cursor: pointer;
}

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

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    border-radius: 20px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: 0 4px 15px rgba(0,0,0,0.03);
}

.card-front {
    /* Front visible initially */
}

.card-back {
    transform: rotateY(180deg);
    background: rgba(255,255,255,0.9);
}

/* Card Content Styling */
.word-chinese {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 5px;
}

.word-pinyin {
    font-size: 1.4rem;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 20px;
}

.audio-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(109, 138, 255, 0.1);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    border: none;
    cursor: pointer;
    transition: all 0.3s;
}

.audio-btn:hover {
    background: var(--primary-color);
    color: white;
    transform: scale(1.1);
}

.audio-btn.playing {
    animation: pulse 1s infinite;
    background: var(--success);
    color: white;
}

.word-vietnamese {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 10px;
}

.word-english {
    font-size: 1.1rem;
    color: var(--text-muted);
}

.mark-learned-btn {
    margin-top: 20px;
    padding: 8px 15px;
    border-radius: 20px;
    border: 1px solid var(--success);
    background: transparent;
    color: var(--success);
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-weight: 600;
}

.mark-learned-btn:hover {
    background: var(--success);
    color: white;
}

.card-scene.learned .card-face {
    border: 2px solid var(--success);
}
.card-scene.learned .mark-learned-btn {
    background: var(--success);
    color: white;
}

.card-typing-inline {
    margin-top: 15px;
    width: 100%;
}

.card-pinyin-input {
    width: 80%;
    padding: 8px 12px;
    border: 2px solid rgba(0,0,0,0.1);
    border-radius: 8px;
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: all 0.3s;
    background: rgba(255,255,255,0.9);
}

.card-pinyin-input:focus {
    border-color: var(--primary-color);
}

.card-pinyin-input.correct {
    border-color: var(--success);
    background-color: rgba(74, 222, 128, 0.1);
    color: var(--success);
}

.card-pinyin-input.wrong {
    border-color: #ef4444;
    background-color: rgba(239, 68, 68, 0.1);
    animation: shake 0.4s;
}

/* IME Popup */
.ime-popup {
    position: absolute;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    display: none;
    flex-direction: column;
    z-index: 1000;
    min-width: 250px;
    overflow: hidden;
}

.ime-composing {
    padding: 10px 15px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    letter-spacing: 1px;
}

.ime-candidates {
    display: flex;
    flex-direction: column;
    max-height: 250px;
    overflow-y: auto;
}

.ime-candidate {
    padding: 10px 15px;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    transition: background 0.2s;
}

.ime-candidate:hover, .ime-candidate.selected {
    background: rgba(109, 138, 255, 0.1);
    color: var(--primary-color);
}

.ime-cand-num {
    color: #999;
    font-size: 0.9rem;
    margin-right: 10px;
    width: 15px;
}

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

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Responsive */
@media (max-width: 768px) {
    .header h1 { font-size: 1.8rem; }
    .flashcards-grid { grid-template-columns: repeat(auto-fill, minmax(100%, 1fr)); }
    .card-scene { height: 280px; }
    .word-chinese { font-size: 3.5rem; }
    .typing-container { padding: 20px 15px; }
    .chinese-large { font-size: 3.5rem; }
    .controls { flex-direction: column; }
    .search-box { max-width: 100%; }
}

.card-image {
    width: 100%;
    max-height: 140px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 15px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
