:root {
    --primary: #4f46e5;
    --primary-light: #818cf8;
    --primary-dark: #3730a3;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-sub: #64748b;
    --border: #e2e8f0;
    --radius: 16px;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg);
    color: var(--text-main);
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    line-height: 1.5;
    padding-bottom: 90px;
}

/* Header */
.app-header {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-weight: 800;
    font-size: 1.3rem;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.icon-btn {
    background: #f1f5f9;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:active { transform: scale(0.9); }

/* Layout Container */
.container {
    padding: 20px;
    max-width: 600px;
    margin: 0 auto;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    border: 1px solid var(--border);
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}

.badge {
    background: #eef2ff;
    color: var(--primary);
    font-size: 0.75rem;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 700;
    text-transform: uppercase;
}

/* Form Elements */
textarea {
    width: 100%;
    height: 110px;
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    font-size: 1rem;
    margin-bottom: 20px;
    background: #fdfdfd;
    transition: all 0.2s;
    resize: none;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-sub);
    margin-bottom: 6px;
}

select {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 2px solid var(--border);
    background: white;
    font-size: 0.95rem;
    color: var(--text-main);
    cursor: pointer;
}

/* Buttons */
.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    padding: 16px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:active { transform: translateY(2px); box-shadow: none; }
.btn-primary:disabled { background: #94a3b8; cursor: not-allowed; }

.btn-secondary {
    background: #f1f5f9;
    color: var(--text-main);
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal-content {
    background: white;
    width: 100%;
    max-width: 400px;
    padding: 30px;
    border-radius: 24px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-content h3 { margin-bottom: 10px; font-size: 1.3rem; }
.desc { color: var(--text-sub); font-size: 0.9rem; margin-bottom: 20px; }

input[type="password"] {
    width: 100%;
    padding: 14px;
    border: 2px solid var(--border);
    border-radius: 10px;
    margin-bottom: 20px;
}

/* Quiz UI */
.quiz-btn {
    width: 100%;
    padding: 14px 18px;
    margin-top: 10px;
    text-align: left;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: white;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
}

.quiz-btn:hover { border-color: var(--primary-light); background: #f5f3ff; }

/* Result Content styling */
.vocab-item {
    padding: 10px;
    border-left: 4px solid var(--primary-light);
    background: #f8fafc;
    margin-bottom: 8px;
    border-radius: 0 8px 8px 0;
}

/* Loader */
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Bottom Nav */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-around;
    padding: 12px 0 25px; /* Thêm padding bottom cho iPhone X+ */
    border-top: 1px solid var(--border);
}

.nav-item {
    text-decoration: none;
    color: var(--text-sub);
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.nav-item.active { color: var(--primary); }

.hidden { display: none !important; }

/* Markdown-like content adjustments */
#contentDisplay p {
    margin-bottom: 15px;
    line-height: 1.7;
    font-size: 1.05rem;
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(15px);
    display: grid;
    grid-template-columns: repeat(5, 1fr); /* Chia đều 5 cột */
    padding: 10px 0 25px;
    border-top: 1px solid var(--border);
    z-index: 1000;
}

.nav-item {
    text-decoration: none;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-icon {
    font-size: 1.4rem;
    transition: transform 0.2s;
}

.nav-label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Hiệu ứng khi Active */
.nav-item.active {
    color: var(--primary);
}

.nav-item.active .nav-icon {
    transform: translateY(-4px) scale(1.2);
}

.nav-item:hover .nav-icon {
    transform: translateY(-2px);
}

/* Hiệu ứng sóng âm giả lập */
.v-bar {
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 3px;
    height: 30px;
}
.v-bar span {
    display: inline-block;
    width: 4px;
    height: 10px;
    background: var(--primary);
    border-radius: 2px;
}

.animating span {
    animation: pulse 0.5s infinite alternate;
}

@keyframes pulse {
    from { height: 10px; }
    to { height: 40px; }
}

#micBtn.recording {
    background: var(--danger);
    animation: ring 1.5s infinite;
    transform: scale(1.1);
}

@keyframes ring {
    0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    100% { box-shadow: 0 0 0 20px rgba(239, 68, 68, 0); }
}

/* Flashcard 3D Flip */
.flashcard {
    background-color: transparent;
    width: 280px;
    height: 350px;
    perspective: 1000px; /* Tạo độ sâu 3D */
    cursor: pointer;
    margin-top: 20px;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    box-shadow: 0 15px 35px rgba(0,0,0,0.1);
    border-radius: 20px;
}

/* Khi có class flipped thì xoay 180 độ */
.flashcard-inner.flipped {
    transform: rotateY(180deg);
}

.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    padding: 20px;
    border: 2px solid var(--primary-light);
}

.flashcard-front {
    background-color: white;
    color: var(--primary);
}

.flashcard-back {
    background-color: var(--primary);
    color: white;
    transform: rotateY(180deg);
}

#card-word { font-size: 2.5rem; margin-bottom: 10px; }
#card-meaning { font-size: 1.5rem; }

/* Toast Notification */
.toast {
    background: white;
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-left: 5px solid var(--primary);
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Chat Bubbles */
.chat-msg {
    max-width: 85%;
    padding: 10px 15px;
    border-radius: 15px;
    margin-bottom: 10px;
    font-size: 0.95rem;
}
.chat-user {
    background: var(--primary);
    color: white;
    align-self: flex-end;
    margin-left: auto;
}
.chat-ai {
    background: #f1f5f9;
    color: var(--text-main);
    align-self: flex-start;
}

/* Tối ưu hóa vùng chạm cho mobile */
.nav-item {
    padding: 12px 0; /* Tăng vùng bấm cho thanh điều hướng */
    min-height: 48px;
}

.btn-primary, .btn-secondary {
    min-height: 44px; /* Tiêu chuẩn Apple/Google cho nút bấm */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Thêm hiệu ứng chuyển cảnh mượt mà giữa các Tab */
.tab-content {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-sub);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
}

.empty-state p {
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 8px;
}

/* Hiệu ứng hướng dẫn cho nút bấm */
.guide-hint {
    font-size: 0.75rem;
    color: var(--primary);
    margin-top: 5px;
    display: block;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
    40% {transform: translateY(-5px);}
    60% {transform: translateY(-3px);}
}

.achievement-card {
    transition: transform 0.3s ease;
}

.achievement-card:hover {
    transform: translateY(-5px); /* Bay nhẹ khi di chuột vào */
}

.stat-box {
    border: 1px solid transparent;
    transition: all 0.2s;
}

.stat-box:hover {
    border-color: var(--primary);
    background: white !important;
    box-shadow: var(--shadow);
}

.achievement-card {
    transition: transform 0.3s ease;
}

.achievement-card:hover {
    transform: translateY(-5px); /* Bay nhẹ khi di chuột vào */
}

.stat-box {
    border: 1px solid transparent;
    transition: all 0.2s;
}

.stat-box:hover {
    border-color: var(--primary);
    background: white !important;
    box-shadow: var(--shadow);
}