:root {
    --bg: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: #e2e8f0;
    --hide-bg: #cbd5e1;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --header-bg: #1e293b;
    --header-text: #ffffff;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-hover: #334155;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --success: #22c55e;
    --warning: #fbbf24;
    --border: #334155;
    --hide-bg: #475569;
    --header-bg: #020617;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text-main);
    transition: background-color 0.3s, color 0.3s;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

h1,
h2,
h3 {
    color: var(--text-main);
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.hidden {
    display: none !important;
}

button,
select {
    cursor: pointer;
    border: none;
    outline: none;
    transition: 0.2s;
    border-radius: 6px;
}

/* Sidebar Navigation */
#sidebar {
    width: 280px;
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 10;
    transition: transform 0.3s;
}

.nav-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 5;
}

/* Auth Section */
#auth-section {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-hover);
    text-align: center;
}

#user-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

#user-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    object-fit: cover;
}

.nav-item {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-item:hover,
.nav-item.active {
    background-color: var(--surface-hover);
    border-left: 4px solid var(--primary);
}

.unit-progress {
    font-size: 0.8rem;
    color: var(--success);
    font-weight: bold;
}

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

#topbar {
    background-color: var(--header-bg);
    color: var(--header-text);
    padding: 15px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow);
    z-index: 5;
}

.progress-container {
    flex: 1;
    max-width: 400px;
    margin: 0 20px;
}

.progress-bar-bg {
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--success);
    width: 0%;
    transition: width 0.5s ease;
}

.topbar-btn {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 8px;
}

.topbar-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

#mobile-menu-btn {
    display: none;
}

/* Sidebar close (×) button — hidden on desktop, shown on mobile via media query */
#sidebar-close-btn {
    display: none;
}

#content-area {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

/* View Toggles & Controls */
.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn,
.filter-select {
    padding: 8px 16px;
    background-color: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    justify-content: center;
}

.btn:hover,
.filter-select:hover {
    background-color: var(--surface-hover);
}

.btn.primary {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn.primary:hover {
    background-color: var(--primary-hover);
}

.btn.danger {
    background-color: #ef4444;
    color: white;
    border-color: #ef4444;
}

.btn.danger:hover {
    background-color: #dc2626;
}

/* Glossary Table View */
.table-container {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th,
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

th {
    background-color: var(--surface-hover);
    font-weight: 600;
    color: var(--text-muted);
    position: sticky;
    top: 0;
    z-index: 2;
}

.type-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    text-transform: uppercase;
    background: var(--border);
    color: var(--text-muted);
}

.speak-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    padding: 4px;
    border-radius: 50%;
    transition: background 0.2s;
}

.speak-btn:hover {
    background: var(--surface-hover);
}

.example-toggle {
    color: var(--primary);
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: underline;
    background: none;
    border: none;
}

.example-box {
    margin-top: 8px;
    padding: 8px;
    background: var(--surface-hover);
    border-left: 3px solid var(--primary);
    border-radius: 4px;
    font-size: 0.9rem;
}

/* Hide/Reveal Magic */
.hideable {
    transition: all 0.2s;
    border-radius: 4px;
    padding: 2px 4px;
    display: inline-block;
}

.hidden-word {
    background-color: var(--hide-bg) !important;
    color: transparent !important;
    cursor: pointer;
    user-select: none;
}

.hidden-word:hover {
    opacity: 0.8;
}

.hidden-word * {
    color: transparent !important;
    visibility: hidden;
}

/* Flashcard View */
.flashcard-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    perspective: 1000px;
}

.flashcard {
    width: 100%;
    height: 320px;
    background: transparent;
    cursor: pointer;
    margin-bottom: 20px;
}

.flashcard-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

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

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 24px;
    background-color: var(--surface);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.flashcard-back {
    transform: rotateY(180deg);
    background-color: var(--surface-hover);
}

.fc-german {
    font-size: 2rem;
    font-weight: bold;
    margin-bottom: 10px;
}

.fc-english {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 20px;
}

.fc-example {
    font-style: italic;
    color: var(--text-muted);
    font-size: 1rem;
    margin-top: 15px;
    border-top: 1px solid var(--border);
    padding-top: 15px;
    width: 100%;
}

.flashcard-controls {
    display: flex;
    gap: 10px;
    width: 100%;
    justify-content: center;
    margin-bottom: 20px;
}

.fc-btn {
    flex: 1;
    padding: 12px;
    font-size: 1rem;
    border-radius: 8px;
    font-weight: bold;
    color: white;
}

.btn-known {
    background-color: var(--success);
}

.btn-learning {
    background-color: var(--warning);
}

.fc-nav {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
    color: var(--text-muted);
    font-weight: bold;
}

/* Dashboard & Trophies */
.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.stat-card {
    background: var(--surface);
    padding: 20px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border);
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary);
    margin: 10px 0;
}

.trophy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.trophy-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    opacity: 0.5;
    filter: grayscale(100%);
    transition: 0.3s;
    position: relative;
}

.trophy-card.earned {
    opacity: 1;
    filter: grayscale(0%);
    border-color: var(--warning);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.2);
}

.trophy-icon {
    font-size: 3rem;
    margin-bottom: 10px;
}

.trophy-title {
    font-weight: bold;
    margin-bottom: 5px;
}

.trophy-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.trophy-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 1.5rem;
    display: none;
}

.trophy-card.earned .trophy-badge {
    display: block;
}

.tier-header {
    grid-column: 1 / -1;
    margin: 25px 0 10px;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
    font-size: 1.1rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tier-header:first-child {
    margin-top: 0;
}

.trophy-card.secret-locked {
    background: var(--surface-hover);
    border-style: dashed;
}

.trophy-card.secret-locked .trophy-icon {
    filter: blur(3px);
    opacity: 0.4;
}

/* Notification Toast */
#toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--surface);
    color: var(--text-main);
    padding: 16px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 0 0 1px var(--warning);
    transform: translateY(150%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 12px;
}

#toast.show {
    transform: translateY(0);
}

/* Sync Status Pill */
#sync-status {
    font-size: 0.8rem;
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 10px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 5px;
}

@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        height: 100%;
        transform: translateX(-100%);
        width: 250px;
        z-index: 100;
    }

    #sidebar.open {
        transform: translateX(0);
    }

    /* Dark overlay behind sidebar on mobile */
    #sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 99;
    }

    #sidebar-overlay.visible {
        display: block;
    }

    /* Close button inside sidebar on mobile */
    #sidebar-close-btn {
        display: flex;
        position: absolute;
        top: 14px;
        right: 14px;
        background: var(--surface-hover);
        border: 1px solid var(--border);
        color: var(--text-main);
        border-radius: 50%;
        width: 30px;
        height: 30px;
        font-size: 1rem;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        padding: 0;
    }

    #mobile-menu-btn {
        display: block;
    }

    .fc-german {
        font-size: 1.5rem;
    }

    .controls-row {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-group {
        justify-content: center;
    }
}

/* Article Quiz */
.quiz-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
}

.quiz-word {
    font-size: 3rem;
    font-weight: bold;
    margin-bottom: 30px;
    text-align: center;
}

.quiz-options {
    display: flex;
    gap: 15px;
    justify-content: center;
    width: 100%;
    max-width: 400px;
}

.quiz-btn {
    flex: 1;
    padding: 15px;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 8px;
    border: 2px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: 0.2s;
}

.quiz-btn:hover {
    background: var(--surface-hover);
    border-color: var(--primary);
}

.quiz-btn.correct {
    background: var(--success);
    color: white;
    border-color: var(--success);
}

.quiz-btn.wrong {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}