/* Base & Variables */
:root {
    --primary-color: #722ed1;
    --primary-hover: #531dab;
    --accent-color: #f3e8ff;
    --bg-color: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-radius: 16px;
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.06);
    --sidebar-width: 320px;
    --heart-color: #ef4444;
    /* Red for heart */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Navbar */
.top-nav {
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
    z-index: 100;
}

.nav-brand {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--primary-color);
}

.nav-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--text-muted);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    min-height: 40px;
}

.icon-btn:active {
    background: #f1f5f9;
    color: var(--primary-color);
}

/* Heart Icon Special Styling */
.fav-btn {
    font-size: 2.2rem;
    /* Larger for mobile touch */
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
    color: #cbd5e1;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.fav-btn.active {
    color: var(--heart-color);
    transform: scale(1.1);
}

.fav-btn:active {
    transform: scale(0.9);
}


.settings-dropdown {
    position: absolute;
    top: 50px;
    right: 8px;
    width: 280px;
    background: white;
    padding: 16px;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    border: 1px solid #e2e8f0;
    z-index: 101;
}

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.content-area main {
    width: 100%;
    max-width: 480px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 40px;
}

.hero-header {
    text-align: center;
    margin-bottom: 12px;
}

.hero-header h1 {
    font-size: 1.75rem;
    margin-bottom: 4px;
}

@media (max-width: 400px) {
    .hero-header {
        display: none;
    }
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-left: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    z-index: 90;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

#sidebarTitle {
    font-weight: 700;
    font-size: 1.1rem;
}

/* Mobile Sidebar Menu (Cards) */
.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 100%;
    transition: opacity 0.3s;
}

.menu-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    transition: 0.2s;
}

.menu-card:active {
    background: #f1f5f9;
    transform: scale(0.98);
}

.menu-icon {
    font-size: 2rem;
}

.menu-text h3 {
    font-size: 1.1rem;
    margin: 0 0 2px 0;
    font-weight: 700;
    color: var(--text-main);
}

.menu-text p {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin: 0;
}

.badge {
    background: #ef4444;
    color: white;
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 700;
    margin-left: 4px;
}

/* User Profile Section */
.user-profile-section {
    padding: 12px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.user-info {
    display: flex;
    gap: 8px;
    align-items: center;
}

.avatar-circle {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
}

.username {
    font-weight: 600;
    font-size: 0.9rem;
}

.text-btn {
    background: none;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-muted);
}

.text-danger {
    color: #ef4444 !important;
    border-color: #fca5a5 !important;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.list-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.history-item {
    background: #f8fafc;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
    position: relative;
}

.history-item:active {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.h-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.h-en {
    font-weight: 600;
    font-size: 1rem;
}

.h-cn {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.h-phonetic {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: monospace;
}

.h-actions {
    margin-top: 8px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Review Card Style within Sidebar */
.review-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.flashcard {
    background: var(--accent-color);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.flashcard .word {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.flashcard .phonetic {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-family: monospace;
}

.flashcard .answer {
    margin-top: 12px;
    font-size: 1rem;
    color: var(--primary-color);
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 12px;
    width: 100%;
}

.review-actions {
    display: flex;
    gap: 8px;
}

.review-btn {
    flex: 1;
    padding: 8px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
}

.btn-forgot {
    background: #ffe4e6;
    color: #e11d48;
}

.btn-remember {
    background: #dcfce7;
    color: #15803d;
}


/* Upload & Preview */
.upload-card {
    background: white;
    padding: 40px 20px;
    border-radius: var(--border-radius);
    text-align: center;
    border: 2px dashed #cbd5e1;
    cursor: pointer;
    transition: 0.3s;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.icon-placeholder {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.8;
}

.image-wrapper {
    background: #000;
    border-radius: var(--border-radius);
    overflow: hidden;
    height: 320px;
    position: relative;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

#imagePreview {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 24px;
    border: none;
    transition: 0.2s;
    z-index: 10;
}

#sidebarBackBtn {
    font-size: 24px;
    margin-right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sidebarBackBtn:hover {
    background: var(--bg-color);
}

/* Result Card */
.result-card {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-soft);
    position: relative;
}

.card-top-actions {
    position: absolute;
    top: 16px;
    right: 16px;
}

.result-header {
    padding-right: 40px;
}

.result-item {
    margin-bottom: 16px;
}

.word-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.speak-btn {
    color: var(--primary-color);
    padding: 4px;
}

.phonetic-text {
    color: var(--text-muted);
    font-family: monospace;
    font-size: 0.95rem;
    margin-top: 4px;
}

.examples-list li {
    background: var(--accent-color);
    padding: 12px;
    border-radius: 12px;
    margin-bottom: 10px;
    border-left: 3px solid var(--primary-color);
    position: relative;
    padding-right: 40px;
}

.ex-speak-btn {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0.7;
    padding: 8px;
}

.divider {
    height: 1px;
    background: #f1f5f9;
    margin: 20px 0;
}

.primary-btn {
    width: 100%;
    padding: 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 14px;
    font-weight: 600;
    font-size: 1.1rem;
    cursor: pointer;
    margin-top: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 56px;
}

.secondary-btn {
    width: 100%;
    padding: 14px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    margin-top: 16px;
    font-weight: 600;
    cursor: pointer;
    min-height: 52px;
}

/* Modal Fixes for Mobile Safari */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    /* Ensure strictly on top */
    /* Mobile Safari Touch Fix */
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}

.modal-card {
    background: white;
    width: 85%;
    max-width: 360px;
    padding: 32px 24px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    position: relative;
    z-index: 10000;
}

@keyframes popUp {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal-card h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.modal-card p {
    color: var(--text-muted);
    margin-bottom: 24px;
}

.input-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.input-group-vertical input {
    padding: 14px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
}

.input-group-vertical input:focus {
    border-color: var(--primary-color);
}

.recent-users {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

.user-chip {
    padding: 6px 12px;
    background: #f1f5f9;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.user-chip:hover {
    background: #e2e8f0;
    color: var(--text-main);
}


/* Loading Dots */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.typing-indicator span {
    display: block;
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 80;
}

.hidden {
    display: none !important;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        right: -100%;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 200;
        /* High z-index to cover everything */
        border-radius: 0;
    }

    /* Ensure header elements don't overlap */
    .sidebar-header {
        padding: 16px 20px;
    }

    .header-nav {
        flex: 1;
        display: flex;
        align-items: center;
        gap: 12px;
        overflow: hidden;
        /* Prevent title overflow */
    }

    #sidebarTitle {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 1.25rem;
    }

    #sidebarBackBtn {
        font-size: 28px;
        /* Larger back button */
        padding: 8px;
        margin-right: 4px;
        /* Reduced margin */
        flex-shrink: 0;
        /* Prevent shrinking */
        width: 44px;
        height: 44px;
        background: rgba(0, 0, 0, 0.05);
        /* Subtle background for better visibility */
    }

    .sidebar.open {
        right: 0;
    }

    .mobile-only {
        display: flex;
    }

    .content-area {
        padding: 12px;
    }

    .nav-brand {
        font-size: 1.1rem;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

.input-group {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.input-group input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 16px;
}

.input-group button {
    padding: 0 16px;
    background: #333;
    color: white;
    border-radius: 8px;
    border: none;
    font-weight: 600;
}

#closeSidebarBtn {
    display: none !important;
}