/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --border-radius: 8px;
    --transition: all 0.2s ease;
}

[data-theme="dark"] {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border-color: #334155;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.3);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3);
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: var(--transition);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header */
.header {
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.logo-icon {
    font-size: 1.8rem;
}

.tagline {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-left: 2.3rem;
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    background: transparent;
    color: var(--text-primary);
}

.btn:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

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

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

.btn-secondary {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

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

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

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

.btn-icon {
    padding: 0.5rem;
    min-width: 2.5rem;
}

.btn-back {
    background: none;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
}

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

/* Main Content */
.main {
    padding: 2rem 0;
    min-height: calc(100vh - 120px);
}

.module-section {
    display: none;
}

.module-section.active,
.dashboard.active {
    display: block;
}

/* Dashboard */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.module-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    text-align: center;
    transition: var(--transition);
    cursor: pointer;
}

.module-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.module-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.module-card h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.module-card p {
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    max-width: 400px;
    margin: 0 auto;
}

.stat-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1rem;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 600;
    color: var(--primary-color);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Module Headers */
.module-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.module-header h2 {
    font-size: 1.875rem;
    font-weight: 600;
}

/* Typing Module */
.typing-controls {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.time-selector {
    display: flex;
    gap: 0.5rem;
    background-color: var(--bg-secondary);
    padding: 0.25rem;
    border-radius: var(--border-radius);
}

.btn-time {
    padding: 0.5rem 1rem;
    border-radius: calc(var(--border-radius) - 2px);
}

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

.typing-area {
    max-width: 800px;
    margin: 0 auto;
}

.typing-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat {
    text-align: center;
    background-color: var(--bg-secondary);
    padding: 1rem;
    border-radius: var(--border-radius);
}

.stat-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.passage-container {
    background-color: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
    min-height: 120px;
}

.passage-text {
    font-size: 1.125rem;
    line-height: 1.8;
    font-family: 'Courier New', monospace;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.char-correct {
    background-color: var(--success-color);
    color: white;
}

.char-incorrect {
    background-color: var(--danger-color);
    color: white;
}

.char-current {
    background-color: var(--primary-color);
    color: white;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

.typing-input {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 1rem;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    resize: none;
    min-height: 100px;
}

.typing-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Quiz Module */
.quiz-setup {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin: 2rem 0;
}

.category-card {
    background-color: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
}

.category-card:hover,
.category-card.selected {
    border-color: var(--primary-color);
    background-color: var(--primary-color);
    color: white;
}

.quiz-options {
    margin-top: 2rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    justify-content: center;
}

.checkbox-label input[type="checkbox"] {
    margin: 0;
}

.quiz-game {
    max-width: 800px;
    margin: 0 auto;
}

.quiz-progress {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background-color: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
}

.progress-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    min-width: 60px;
}

.question-container {
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 2rem;
    margin-bottom: 2rem;
}

.question-text {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.choices-container {
    display: grid;
    gap: 0.75rem;
}

.choice-btn {
    width: 100%;
    padding: 1rem;
    text-align: left;
    background-color: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-primary);
}

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

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

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

.choice-btn.incorrect {
    background-color: var(--danger-color);
    color: white;
    border-color: var(--danger-color);
}

.quiz-controls {
    text-align: center;
}

/* Flashcards Module */
.deck-selection {
    max-width: 800px;
    margin: 0 auto;
}

.decks-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1rem;
}

.deck-card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.deck-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.deck-card h3 {
    margin-bottom: 0.5rem;
}

.deck-card p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.deck-actions {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0.25rem;
}

.flashcard-study {
    max-width: 600px;
    margin: 0 auto;
}

.study-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.card-counter {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

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

.flashcard {
    width: 100%;
    height: 300px;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    cursor: pointer;
}

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

.flashcard-front,
.flashcard-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: var(--border-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background-color: var(--bg-secondary);
    border: 2px solid var(--border-color);
}

.flashcard-back {
    transform: rotateY(180deg);
    background-color: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.card-content {
    text-align: center;
    font-size: 1.25rem;
    line-height: 1.6;
}

.flashcard-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background-color: var(--bg-primary);
    border-radius: var(--border-radius);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

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

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

.cards-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-editor {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
    padding: 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
}

.card-editor input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Profile Panel */
.profile-panel {
    position: fixed;
    top: 0;
    right: -400px;
    width: 400px;
    height: 100vh;
    background-color: var(--bg-primary);
    border-left: 1px solid var(--border-color);
    transition: right 0.3s ease;
    z-index: 999;
    overflow-y: auto;
}

.profile-panel.active {
    right: 0;
}

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

.profile-content {
    padding: 1.5rem;
}

.profile-section {
    margin-bottom: 2rem;
}

.profile-section h4 {
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.badges-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.badge {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 0.75rem;
    text-align: center;
    font-size: 0.875rem;
}

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

.leaderboard-tabs {
    display: flex;
    margin-bottom: 1rem;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 0.25rem;
}

.tab-btn {
    flex: 1;
    padding: 0.5rem;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: calc(var(--border-radius) - 2px);
    transition: var(--transition);
}

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

.leaderboard-entry {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    margin-bottom: 0.5rem;
}

.leaderboard-rank {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 30px;
}

.leaderboard-name {
    flex: 1;
    margin-left: 0.75rem;
}

.leaderboard-score {
    font-weight: 500;
}

/* Results Panel */
.results-panel {
    max-width: 500px;
    margin: 2rem auto;
    background-color: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 2rem;
    text-align: center;
}

.results-panel.hidden {
    display: none;
}

.results-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.result-stat {
    background-color: var(--bg-primary);
    padding: 1rem;
    border-radius: var(--border-radius);
}

.result-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

.result-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

.results-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.results-actions input {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--bg-primary);
    color: var(--text-primary);
}

/* Utility Classes */
.hidden {
    display: none !important;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 0.75rem;
    }
    
    .header .container {
        flex-direction: column;
        text-align: center;
    }
    
    .tagline {
        margin-left: 0;
    }
    
    .modules-grid {
        grid-template-columns: 1fr;
    }
    
    .typing-stats {
        grid-template-columns: 1fr;
    }
    
    .flashcard-controls {
        flex-direction: column;
    }
    
    .profile-panel {
        width: 100%;
        right: -100%;
    }
    
    .modal-content {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
    }
    
    .card-editor {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
}

@media (max-width: 480px) {
    .main {
        padding: 1rem 0;
    }
    
    .module-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .results-actions {
        gap: 0.5rem;
    }
    
    .flashcard {
        height: 250px;
    }
    
    .card-content {
        font-size: 1rem;
    }
}

/* Focus and Accessibility */
.btn:focus,
.choice-btn:focus,
.flashcard:focus,
input:focus,
textarea:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

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

.module-section.active {
    animation: fadeIn 0.3s ease;
}

/* Print Styles */
@media print {
    .header-controls,
    .btn,
    .profile-panel {
        display: none;
    }
}