:root {
    --bg-dark: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.7);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-neon: #38bdf8;
    --accent-neon-glow: rgba(56, 189, 248, 0.5);
    --success: #10b981;
    --warning: #f59e0b;
    --card-border: rgba(255, 255, 255, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(56, 189, 248, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(56, 189, 248, 0.05) 0%, transparent 50%);
    overflow-x: hidden;
}

.app-layout {
    display: flex;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: rgba(15, 23, 42, 0.9);
    border-right: 1px solid var(--card-border);
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    position: sticky;
    top: 0;
}

.sidebar-header h2 {
    font-size: 1.2rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    font-weight: 600;
}

.mastered-card {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(56, 189, 248, 0.1));
    border: 1px solid rgba(16, 185, 129, 0.3);
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 1rem;
    transition: all 0.2s ease;
}

.mastered-card:hover {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(56, 189, 248, 0.2));
    transform: translateX(4px);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.2);
}

.mastered-card-icon {
    font-size: 1.5rem;
}

.mastered-card-info {
    display: flex;
    flex-direction: column;
}

.mastered-card-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--success);
}

.mastered-card-count {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.history-list {
    list-style: none;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    padding-right: 0.5rem;
}

/* Custom Scrollbar for sidebar */
.history-list::-webkit-scrollbar {
    width: 6px;
}
.history-list::-webkit-scrollbar-track {
    background: transparent;
}
.history-list::-webkit-scrollbar-thumb {
    background: var(--card-border);
    border-radius: 4px;
}

.history-item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative; /* Needed for delete button positioning */
}

.history-item:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: rgba(56, 189, 248, 0.3);
    transform: translateX(4px);
}

.history-delete-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    opacity: 0; /* Hidden by default */
    transition: opacity 0.2s, color 0.2s;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-item:hover .history-delete-btn {
    opacity: 0.6; /* Show on hover of the list item */
}

.history-delete-btn:hover {
    opacity: 1 !important;
    color: #ef4444; /* Red color on hover */
    background: rgba(239, 68, 68, 0.1);
}

.history-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    margin-bottom: 0.2rem;
    line-height: 1.3;
}

.history-url {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    margin-bottom: 0.5rem;
    opacity: 0.6;
}

.history-stats-container {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.history-stat-badge {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.2rem 0.5rem;
    border-radius: 12px;
    letter-spacing: 0.5px;
}

.stat-total {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.stat-review {
    background: rgba(56, 189, 248, 0.1);
    color: var(--accent-neon);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.app-container {
    flex: 1;
    max-width: 1000px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    margin: 0 auto;
}

/* Header & Stats */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent-neon);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent-neon-glow);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 var(--accent-neon-glow); }
    70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(56, 189, 248, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

.stats {
    display: flex;
    gap: 1.5rem;
}

.stat-box {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--accent-neon);
}

/* Views */
.view {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Glass Panels */
.glass-panel {
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 3rem;
    backdrop-filter: blur(12px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.subtitle {
    color: var(--text-secondary);
    margin-top: 0.5rem;
    margin-bottom: 2rem;
}

/* Form Elements */
.input-group {
    display: flex;
    gap: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

input[type="text"] {
    flex: 1;
    padding: 1rem 1.5rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    transition: all 0.3s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-neon);
    box-shadow: 0 0 15px var(--accent-neon-glow);
}

button {
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    border: none;
    transition: all 0.2s ease;
}

.primary-btn {
    padding: 0 2rem;
    background: linear-gradient(135deg, #0ea5e9, #38bdf8);
    color: white;
    font-weight: 600;
    font-size: 1rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 160px;
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
}

.primary-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14, 165, 233, 0.5);
}

.primary-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.hidden {
    display: none !important;
}

/* Learning View */
.learning-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

/* Flashcard */
.flashcard-container {
    perspective: 1000px;
    margin-bottom: 2rem;
}

.flashcard {
    width: 100%;
    max-width: 600px;
    height: 400px;
    margin: 0 auto;
    background: transparent;
    cursor: pointer;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transform-style: preserve-3d;
}

.flashcard-front, .flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 3rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(16px);
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
}

.flashcard-back {
    transform: rotateY(180deg);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.8) 0%, rgba(15, 23, 42, 0.9) 100%);
    border: 1px solid rgba(56, 189, 248, 0.3);
}

.word-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
}

.target-word {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
    letter-spacing: -1px;
    text-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

.phonetics {
    font-size: 1.2rem;
    color: var(--text-secondary);
    font-family: 'Segoe UI', monospace;
    letter-spacing: 1px;
}

.audio-btn {
    background: rgba(56, 189, 248, 0.1);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: var(--accent-neon);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 0.5rem;
}

.audio-btn:hover {
    background: rgba(56, 189, 248, 0.2);
    transform: scale(1.1);
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
}

.audio-btn.speaking {
    background: rgba(56, 189, 248, 0.25);
    box-shadow: 0 0 20px rgba(56, 189, 248, 0.6);
    animation: speakingPulse 0.8s ease-in-out infinite;
}

@keyframes speakingPulse {
    0% { transform: scale(1); box-shadow: 0 0 10px rgba(56, 189, 248, 0.4); }
    50% { transform: scale(1.15); box-shadow: 0 0 25px rgba(56, 189, 248, 0.7); }
    100% { transform: scale(1); box-shadow: 0 0 10px rgba(56, 189, 248, 0.4); }
}

.hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
    opacity: 0.7;
    margin-top: 1.5rem;
}

.target-translation {
    font-size: 2.5rem;
    color: var(--accent-neon);
    margin-bottom: 2rem;
}

.context-container {
    text-align: left;
    width: 100%;
    padding-top: 2rem;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.context-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 1rem;
}

.context-en {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 0.5rem;
    color: #e2e8f0;
}

.context-cn {
    font-size: 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    visibility: hidden; /* Hidden until flipped */
    opacity: 0;
    transition: opacity 0.3s;
}

.action-buttons.visible {
    visibility: visible;
    opacity: 1;
}

.action-btn {
    padding: 1rem 2rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    color: white;
}

.review-btn {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.3);
    color: var(--warning);
}
.review-btn:hover { background: rgba(245, 158, 11, 0.2); }

.known-btn {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.3);
    color: var(--success);
}
.known-btn:hover { background: rgba(16, 185, 129, 0.2); box-shadow: 0 0 15px rgba(16, 185, 129, 0.2); }

.mt-4 { margin-top: 2rem; }
.error-text { color: #f43f5e; margin-top: 1rem; font-size: 0.9rem; }

/* Sidebar header layout with button */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.sidebar-header h2 {
    margin-bottom: 0;
}

/* Sidebar "New Lesson" button */
.new-lesson-btn {
    padding: 0.5rem 0.85rem;
    font-size: 0.8rem;
    min-width: auto;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}
.new-lesson-btn.active {
    background: linear-gradient(135deg, #0369a1, #0ea5e9);
    box-shadow: 0 0 12px rgba(14, 165, 233, 0.5);
}

/* Collapsible sidebar input panel */
.sidebar-input-panel {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    animation: fadeIn 0.25s ease-out;
}
.sidebar-input-panel input[type="text"] {
    padding: 0.7rem 1rem;
    font-size: 0.85rem;
    border-radius: 10px;
    width: 100%;
}
.sidebar-input-panel .primary-btn {
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    min-width: auto;
    width: 100%;
    height: auto;
    border-radius: 10px;
}

/* Home dashboard (mastered words as default) */
.home-dashboard {
    max-width: 500px;
    margin: 4rem auto;
}
.dashboard-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: float 3s ease-in-out infinite;
}
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
.mastered-home-count {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0.5rem 0 1.5rem;
}
.mastered-home-count strong {
    color: var(--success);
    font-size: 1.2rem;
}
.home-dashboard .primary-btn {
    margin: 0 auto;
    padding: 0.9rem 2.5rem;
    font-size: 1rem;
    height: auto;
}
.hint-small {
    margin-top: 1.5rem;
    font-size: 0.82rem;
    color: var(--text-secondary);
    opacity: 0.7;
}
.hint-small strong {
    color: var(--accent-neon);
}

