/* ===== CSS Variables & Reset ===== */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #161822;
    --bg-card: #1c1f2e;
    --bg-card-hover: #242838;
    --bg-sidebar: #131520;
    --bg-input: #1a1d2b;
    --text-primary: #e8eaf0;
    --text-secondary: #9ca3b8;
    --text-muted: #6b7280;
    --accent: #6c5ce7;
    --accent-light: #a29bfe;
    --accent-glow: rgba(108, 92, 231, 0.3);
    --accent-gradient: linear-gradient(135deg, #6c5ce7, #a29bfe);
    --success: #00cec9;
    --success-bg: rgba(0, 206, 201, 0.12);
    --danger: #ff6b6b;
    --danger-bg: rgba(255, 107, 107, 0.12);
    --warning: #feca57;
    --border: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --sidebar-width: 280px;
    --topbar-height: 64px;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* ===== App Layout ===== */
.app-container { display: flex; height: 100vh; overflow: hidden; }

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform var(--transition), width var(--transition);
    z-index: 100;
    position: relative;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 28px; filter: drop-shadow(0 0 8px var(--accent-glow)); }
.logo-text h1 {
    font-size: 1.15rem; font-weight: 700;
    background: var(--accent-gradient); -webkit-background-clip: text;
    -webkit-text-fill-color: transparent; background-clip: text;
    line-height: 1.3;
}
.logo-subtitle { font-size: 0.7rem; color: var(--text-muted); font-weight: 400; }

.sidebar-toggle {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 6px; border-radius: var(--radius-sm);
    transition: var(--transition);
}
.sidebar-toggle:hover { color: var(--text-primary); background: var(--bg-card); }

.sidebar-search { padding: 16px 20px 8px; }
.search-box {
    position: relative; display: flex; align-items: center;
    background: var(--bg-input); border-radius: var(--radius-sm);
    border: 1px solid var(--border); transition: var(--transition);
}
.search-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-icon { position: absolute; left: 12px; color: var(--text-muted); }
.search-box input {
    width: 100%; padding: 10px 12px 10px 36px; background: none;
    border: none; color: var(--text-primary); font-size: 0.85rem;
    font-family: inherit; outline: none;
}
.search-box input::placeholder { color: var(--text-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 12px; }
.nav-section-title {
    font-size: 0.7rem; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 1px;
    padding: 8px 8px 4px; margin-top: 4px;
}
.nav-list { list-style: none; }

.nav-item {
    padding: 10px 14px; margin: 2px 0;
    border-radius: var(--radius-sm); cursor: pointer;
    display: flex; align-items: center; gap: 10px;
    transition: var(--transition); color: var(--text-secondary);
    font-size: 0.88rem; font-weight: 500; position: relative;
}
.nav-item:hover { background: var(--bg-card); color: var(--text-primary); }
.nav-item.active {
    background: var(--accent-glow); color: var(--accent-light);
    border-left: 3px solid var(--accent);
}
.nav-item .nav-icon { font-size: 1rem; }
.nav-item .nav-count {
    margin-left: auto; font-size: 0.72rem; color: var(--text-muted);
    background: var(--bg-input); padding: 2px 8px;
    border-radius: 10px; font-weight: 600;
}

.sidebar-footer {
    padding: 16px 20px; border-top: 1px solid var(--border);
}
.stats { display: flex; gap: 16px; }
.stat-item { display: flex; flex-direction: column; align-items: center; flex: 1; }
.stat-number {
    font-size: 1.3rem; font-weight: 700;
    background: var(--accent-gradient); -webkit-background-clip: text;
    -webkit-text-fill-color: transparent; background-clip: text;
}
.stat-label { font-size: 0.7rem; color: var(--text-muted); }

/* ===== Main Content ===== */
.main-content {
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden; position: relative;
}

/* ===== Top Bar ===== */
.top-bar {
    height: var(--topbar-height); padding: 0 24px;
    display: flex; align-items: center; gap: 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(15, 17, 23, 0.8);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    z-index: 10;
}
.menu-btn {
    display: none; background: none; border: none;
    color: var(--text-secondary); cursor: pointer; padding: 4px;
}
.top-bar-title {
    font-size: 1rem; font-weight: 600; color: var(--text-secondary); flex: 1;
}
.top-bar-actions { display: flex; gap: 8px; }
.action-btn {
    display: flex; align-items: center; gap: 6px; padding: 8px 14px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-secondary);
    cursor: pointer; font-size: 0.82rem; font-weight: 500;
    transition: var(--transition); font-family: inherit;
}
.action-btn:hover {
    background: var(--bg-card-hover); color: var(--text-primary);
    border-color: var(--border-light);
}
.action-btn.quiz-btn:hover { border-color: var(--accent); color: var(--accent-light); }

/* ===== Welcome Screen ===== */
.welcome-screen {
    flex: 1; display: flex; align-items: center; justify-content: center;
    padding: 40px;
}
.welcome-content { text-align: center; max-width: 700px; }
.welcome-icon {
    font-size: 64px; margin-bottom: 20px; display: block;
    animation: float 3s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-12px); }
}
.welcome-content h2 {
    font-size: 1.8rem; font-weight: 700; margin-bottom: 10px;
    background: var(--accent-gradient); -webkit-background-clip: text;
    -webkit-text-fill-color: transparent; background-clip: text;
}
.welcome-content > p { color: var(--text-muted); font-size: 1rem; margin-bottom: 36px; }
.welcome-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; }
.feature-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 24px 16px;
    transition: var(--transition);
}
.feature-card:hover {
    transform: translateY(-4px); border-color: var(--accent-glow);
    box-shadow: 0 8px 24px rgba(108, 92, 231, 0.15);
}
.feature-icon { font-size: 32px; display: block; margin-bottom: 12px; }
.feature-card h3 { font-size: 0.9rem; font-weight: 600; margin-bottom: 4px; }
.feature-card p { font-size: 0.75rem; color: var(--text-muted); }

/* ===== Word List View ===== */
.word-list-view { flex: 1; overflow-y: auto; padding: 24px; }
.list-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.list-title { font-size: 1.4rem; font-weight: 700; }
.list-count {
    font-size: 0.8rem; color: var(--text-muted); font-weight: 500;
    background: var(--bg-card); padding: 4px 12px;
    border-radius: 20px; margin-left: 12px;
}
.view-toggles { display: flex; gap: 4px; }
.view-toggle {
    padding: 8px 10px; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-muted); cursor: pointer; transition: var(--transition);
}
.view-toggle:hover { color: var(--text-primary); }
.view-toggle.active {
    background: var(--accent-glow); color: var(--accent-light);
    border-color: var(--accent);
}

/* ===== Card View ===== */
.words-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.word-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-md); padding: 20px;
    transition: var(--transition); cursor: default;
    position: relative; overflow: hidden;
    animation: cardIn 0.4s ease-out backwards;
}
@keyframes cardIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
.word-card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.word-card::before {
    content: ''; position: absolute; top: 0; left: 0;
    width: 100%; height: 3px;
    background: var(--accent-gradient); opacity: 0;
    transition: var(--transition);
}
.word-card:hover::before { opacity: 1; }

.card-index {
    position: absolute; top: 12px; right: 14px;
    font-size: 0.7rem; color: var(--text-muted);
    font-weight: 600; opacity: 0.5;
}

.card-english {
    font-size: 1.25rem; font-weight: 700; margin-bottom: 8px;
    color: var(--text-primary); display: flex; align-items: center; gap: 8px;
}
.card-chinese {
    font-size: 0.9rem; color: var(--text-secondary); line-height: 1.5;
    font-family: 'Noto Sans SC', sans-serif;
}
.card-chinese.hidden-text {
    filter: blur(8px); user-select: none; cursor: pointer;
    transition: filter 0.3s ease;
}
.card-chinese.hidden-text:hover { filter: blur(4px); }
.card-chinese.hidden-text.revealed { filter: none; cursor: default; user-select: auto; }

.speak-btn {
    background: none; border: none; color: var(--accent-light);
    cursor: pointer; padding: 4px; border-radius: 50%;
    transition: var(--transition); display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.speak-btn:hover { background: var(--accent-glow); transform: scale(1.15); }
.speak-btn.speaking { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ===== Table View ===== */
.words-table-container { overflow-x: auto; }
.words-table {
    width: 100%; border-collapse: separate; border-spacing: 0;
    background: var(--bg-card); border-radius: var(--radius-md);
    overflow: hidden; border: 1px solid var(--border);
}
.words-table thead th {
    padding: 14px 16px; text-align: left; font-size: 0.78rem;
    font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.5px;
    background: var(--bg-sidebar); border-bottom: 1px solid var(--border);
}
.words-table tbody tr {
    transition: var(--transition);
    animation: rowIn 0.3s ease-out backwards;
}
@keyframes rowIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.words-table tbody tr:hover { background: var(--bg-card-hover); }
.words-table tbody td {
    padding: 14px 16px; border-bottom: 1px solid var(--border);
    font-size: 0.92rem;
}
.words-table tbody tr:last-child td { border-bottom: none; }
.col-index { width: 50px; color: var(--text-muted); font-weight: 600; font-size: 0.8rem !important; }
.col-english { font-weight: 600; }
.col-chinese { color: var(--text-secondary); }
.col-actions { width: 60px; text-align: center; }

/* ===== Quiz View ===== */
.quiz-view {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; padding: 32px 24px; overflow-y: auto;
}
.quiz-header { text-align: center; margin-bottom: 24px; width: 100%; max-width: 500px; }
.quiz-header h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 8px; }
.quiz-instruction { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 16px; }
.quiz-progress {
    width: 100%; height: 6px; background: var(--bg-input);
    border-radius: 3px; overflow: hidden; margin-bottom: 12px;
}
.quiz-progress-bar {
    height: 100%; background: var(--accent-gradient);
    border-radius: 3px; transition: width 0.4s ease; width: 0%;
}
.quiz-stats { display: flex; justify-content: center; gap: 24px; font-size: 0.85rem; color: var(--text-secondary); }

.quiz-card-container {
    width: 100%; max-width: 420px; perspective: 1000px; margin-bottom: 24px;
}
.quiz-card {
    width: 100%; min-height: 220px; position: relative;
    cursor: pointer; transform-style: preserve-3d;
    transition: transform 0.6s ease;
}
.quiz-card.flipped { transform: rotateY(180deg); }
.quiz-card-face {
    position: absolute; width: 100%; min-height: 220px;
    backface-visibility: hidden; -webkit-backface-visibility: hidden;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 32px; border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}
.quiz-card-front {
    background: linear-gradient(145deg, var(--bg-card), var(--bg-card-hover));
    z-index: 2;
}
.quiz-card-back {
    background: linear-gradient(145deg, #1a2332, #1c2638);
    transform: rotateY(180deg);
    border-color: var(--accent-glow);
}
.quiz-card-front .quiz-word {
    font-size: 2rem; font-weight: 800; margin-bottom: 8px;
}
.quiz-card-front .quiz-hint {
    font-size: 0.8rem; color: var(--text-muted);
}
.quiz-card-back .quiz-meaning {
    font-size: 1.3rem; font-weight: 600; color: var(--accent-light);
    font-family: 'Noto Sans SC', sans-serif; text-align: center;
}
.quiz-card-back .quiz-word-back {
    font-size: 0.9rem; color: var(--text-muted); margin-top: 8px;
}

.quiz-actions { display: flex; gap: 16px; margin-bottom: 24px; }
.quiz-action-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 28px; border-radius: var(--radius-md);
    border: 1px solid var(--border); cursor: pointer;
    font-size: 0.95rem; font-weight: 600; font-family: inherit;
    transition: var(--transition);
}
.quiz-action-btn.known {
    background: var(--success-bg); color: var(--success);
    border-color: rgba(0, 206, 201, 0.3);
}
.quiz-action-btn.known:hover {
    background: rgba(0, 206, 201, 0.2);
    box-shadow: 0 0 16px rgba(0, 206, 201, 0.2);
}
.quiz-action-btn.unknown {
    background: var(--danger-bg); color: var(--danger);
    border-color: rgba(255, 107, 107, 0.3);
}
.quiz-action-btn.unknown:hover {
    background: rgba(255, 107, 107, 0.2);
    box-shadow: 0 0 16px rgba(255, 107, 107, 0.2);
}

.quiz-result { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(15,17,23,0.9); backdrop-filter: blur(8px); z-index: 10; }
.result-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-xl); padding: 40px;
    text-align: center; max-width: 400px; width: 90%;
    animation: cardIn 0.5s ease-out;
}
.result-emoji { font-size: 56px; margin-bottom: 16px; }
.result-card h3 { font-size: 1.4rem; font-weight: 700; margin-bottom: 8px; }
.result-card p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }
.result-stats { display: flex; justify-content: center; gap: 32px; margin-bottom: 28px; }
.result-stat { display: flex; flex-direction: column; align-items: center; }
.result-stat-number { font-size: 2rem; font-weight: 800; }
.known-stat .result-stat-number { color: var(--success); }
.unknown-stat .result-stat-number { color: var(--danger); }
.result-stat-label { font-size: 0.78rem; color: var(--text-muted); }
.result-actions { display: flex; flex-direction: column; gap: 8px; }
.result-btn {
    padding: 10px 20px; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-input);
    color: var(--text-secondary); cursor: pointer;
    font-size: 0.88rem; font-weight: 500; font-family: inherit;
    transition: var(--transition);
}
.result-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.result-btn.primary {
    background: var(--accent-gradient); color: white;
    border: none; font-weight: 600;
}
.result-btn.primary:hover { opacity: 0.9; transform: scale(1.02); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        position: fixed; top: 0; left: 0; height: 100vh;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: translateX(0); }
    .menu-btn { display: block; }
    .words-grid { grid-template-columns: 1fr; }
    .action-btn span { display: none; }
    .top-bar-actions { gap: 4px; }
}
@media (max-width: 480px) {
    .welcome-features { grid-template-columns: repeat(2, 1fr); }
    .quiz-card-front .quiz-word { font-size: 1.5rem; }
}
