:root {
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --primary: #6366f1;
    /* Indigo 500 */
    --primary-hover: #4f46e5;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --glass: rgba(30, 41, 59, 0.7);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, 'Noto Sans TC', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    font-size: 1.2rem;
    color: var(--primary);
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 12px;
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
}

.tags-section {
    margin-top: 40px;
    flex: 1;
    overflow-y: auto;
}

.tags-section h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 15px;
    letter-spacing: 1px;
}

.tags-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-chip {
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    cursor: pointer;
    border: 1px solid transparent;
}

.tag-chip:hover,
.tag-chip.active {
    border-color: var(--primary);
    color: var(--primary);
}

/* Form Select Styling */
.form-select {
    width: 100%;
    padding: 12px 16px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.3s ease;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px;
}

.form-select:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.08);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
}

.form-select option {
    background: #1e1b4b;
    /* Matches dark theme */
    color: var(--text-main);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
}

.top-bar {
    height: 80px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    backdrop-filter: blur(10px);
    background: rgba(15, 23, 42, 0.8);
    overflow: visible;
    /* Ensure content isn't clipped */
}

.actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.search-bar {
    position: relative;
    width: 300px;
}

.search-bar i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 18px;
}

.search-bar input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    padding: 10px 10px 10px 40px;
    border-radius: 8px;
    color: white;
    outline: none;
}

.search-bar input:focus {
    border-color: var(--primary);
}

.btn {
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
    transition: transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* View Section */
.view-section {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.filter-bar {
    margin-bottom: 20px;
    display: flex;
    gap: 15px;
    align-items: center;
}

select {
    background: var(--bg-card);
    color: white;
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 6px;
    outline: none;
}

.words-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    /* Increased min-width to accommodate buttons */
    gap: 20px;
}

.word-card {
    background: rgba(30, 41, 59, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 24px;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: default;
    display: flex;
    flex-direction: column;
    min-height: 200px;
    /* Ensure a minimum height for better alignment */
}

/* Disable transitions when sorting is active to prevent lag */

.word-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    border-color: var(--primary);
}



.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    /* Push to bottom */
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    flex-wrap: wrap;
    /* Prevent overflow on zoom */
    gap: 10px;
}

.action-group,
.move-group {
    display: flex;
    gap: 4px;
    /* Tighter gap for smaller buttons */
}

.move-separator {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 5px;
    opacity: 0.5;
}

.btn-quick {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 34px;
    /* Optimized smaller size */
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-quick i {
    width: 16px;
    height: 16px;
}

.btn-quick:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.1);
}



/* SortableJS Styles */
.sortable-ghost {
    opacity: 0.2;
    border: 2px dashed var(--primary);
    background: transparent !important;
}

.sortable-chosen {
    transform: scale(1.05) rotate(2deg);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.sortable-drag {
    opacity: 0.9;
    transform: scale(1.05) rotate(0deg) !important;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.8) !important;
    background: var(--bg-card) !important;
    border: 2px solid var(--primary) !important;
    z-index: 10000;
}

.jump-highlight {
    animation: pulse-border 1.5s ease-out;
    border-color: var(--primary) !important;
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.6) !important;
}

@keyframes pulse-border {
    0% {
        transform: scale(1.05);
        border-color: var(--primary);
    }

    50% {
        transform: scale(1.02);
        border-color: #818cf8;
    }

    100% {
        transform: scale(1);
        border-color: rgba(255, 255, 255, 0.05);
    }
}

.word-card.search-highlight {
    border-color: #fbbf24;
    /* Amber 400 */
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.4);
    background: rgba(251, 191, 36, 0.1);
    transform: scale(1.02);
    z-index: 10;
}

.word-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.word-info {
    flex: 1;
}

.card-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.word-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    word-break: break-word;
    /* Force break long words */
    overflow-wrap: break-word;
    line-height: 1.2;
}

.word-phonetic {
    font-family: 'Noto Sans TC', sans-serif;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

.word-def-cn {
    font-size: 1.1rem;
    color: #cbd5e1;
    margin-bottom: 6px;
}

.word-def-en {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-style: italic;
    line-height: 1.4;
}

.word-notes {
    margin-top: 8px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    font-size: 0.85rem;
    color: #94a3b8;
    border-left: 2px solid var(--primary);
}

.card-tags {
    margin-top: 15px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.mini-tag {
    font-size: 0.7rem;
    padding: 2px 8px;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    border-radius: 10px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.hidden {
    display: none;
}

.modal {
    background: var(--bg-card);
    width: 600px;
    max-width: 90%;
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 20px;
    max-height: 70vh;
    overflow-y: auto;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 6px;
    color: white;
    font-family: inherit;
}

.row {
    display: flex;
    gap: 15px;
}

.col {
    flex: 1;
}

.input-group {
    display: flex;
    gap: 8px;
}

.btn-small {
    padding: 0 12px;
    background: var(--primary);
    border: none;
    color: white;
    border-radius: 6px;
    cursor: pointer;
}

/* Learning Mode */
.learning-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 80%;
}

.flashcard {
    background: var(--bg-card);
    width: 500px;
    /* Wider card */
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    border: 2px solid var(--border);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.flashcard h2 {
    font-size: 3rem;
    margin-bottom: 10px;
    color: white;
}

.learn-controls {
    display: flex;
    flex-direction: column;
    /* Stack input and buttons if needed, or align row */
    gap: 15px;
    margin-top: 30px;
    align-items: center;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 34px;
    /* Optimized smaller size */
    height: 34px;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
}

.btn-icon:hover {
    background: var(--primary);
    transform: scale(1.1);
}

.btn-icon:active {
    transform: scale(0.9);
}

.btn-icon i,
.btn-icon svg {
    pointer-events: none !important;
}

#learn-input {
    font-size: 1.5rem;
    text-align: center;
    padding: 10px;
    margin: 20px auto 40px auto;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--border);
    color: var(--primary);
    width: 60%;
    display: block;
}

#learn-input:focus {
    border-color: var(--primary);
    outline: none;
}

/* Stats Dashboard Enhancements */
.stats-overview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.stat-icon i {
    width: 24px;
    height: 24px;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: white;
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Premium Card Colors */
.premium-card-1 .stat-icon {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.premium-card-2 .stat-icon {
    background: linear-gradient(135deg, #ec4899, #d946ef);
}

.premium-card-3 .stat-icon {
    background: linear-gradient(135deg, #10b981, #059669);
}

.premium-card-4 .stat-icon {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.premium-card-5 .stat-icon {
    background: linear-gradient(135deg, #06b6d4, #0891b2);
}

.chart-panel {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 25px;
    margin-bottom: 30px;
}

.chart-panel h3 {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    color: var(--text-main);
}

.chart-container {
    height: 250px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.stats-panel {
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 25px;
}

.stats-panel h3 {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
}

.tag-stat-item {
    margin-bottom: 15px;
}

.tag-name-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.progress-bar-bg {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.weak-word-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    margin-bottom: 8px;
}

.weak-word-text {
    font-weight: 600;
}

.error-badge {
    font-size: 0.75rem;
    padding: 4px 8px;
    background: rgba(248, 113, 113, 0.2);
    color: #f87171;
    border-radius: 4px;
}