/* ===== ROOT & MOBILE-FIRST ===== */
:root {
    --primary: #7c3aed;
    --primary-dark: #6d28d9;
    --secondary: #06b6d4;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --bg: #f9fafb;
    --bg-card: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

html, body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg);
    height: 100%;
    overflow: hidden;
}

body {
    display: flex;
    align-items: center;
    justify-content: center;
}

#app {
    width: 100%;
    height: 100%;
    max-width: 768px;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    position: relative;
}

/* ===== SCREENS ===== */
.screen {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
    opacity: 1;
    transition: opacity 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
}

.screen.hidden {
    display: none;
    opacity: 0;
    z-index: 0;
}

/* ===== HEADER ===== */
.app-header {
    padding: 20px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    text-align: center;
    box-shadow: var(--shadow);
}

.app-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.app-header .subtitle {
    font-size: 12px;
    opacity: 0.9;
    font-weight: 400;
}

.quiz-header {
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--shadow);
}

.quiz-header h2 {
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
    overflow: hidden;
}

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

.progress-text {
    font-size: 12px;
    text-align: right;
    opacity: 0.9;
}

/* ===== BUTTONS ===== */
.btn {
    padding: 12px 16px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    min-width: 44px;
    touch-action: manipulation;
}

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

.btn-primary:active {
    background: var(--primary-dark);
    transform: scale(0.98);
}

.btn-submit {
    background: var(--success);
    color: white;
    width: 100%;
}

.btn-submit:active {
    background: #059669;
    transform: scale(0.98);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid var(--border);
    width: 100%;
}

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

.btn-back {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-back:active {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== CONTENT AREA ===== */
.content {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.content h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

/* ===== STATS ===== */
.stats-mini {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 0 16px;
    margin-top: -8px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    background: var(--bg-card);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.stats-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow);
}

.stats-card h3 {
    margin-bottom: 12px;
    font-size: 16px;
}

/* ===== THEMES GRID ===== */
.themes-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 12px;
}

.theme-btn {
    padding: 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    font-weight: 600;
    font-size: 14px;
}

.theme-btn:active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(0.95);
}

/* ===== QUIZ CARD ===== */
.quiz-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
    overflow-y: auto;
    justify-content: center;
}

.card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 24px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.card-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-question {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.4;
    word-break: break-word;
}

/* ===== ANSWER SECTION ===== */
.answer-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.answer-input {
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    background: var(--bg-card);
    color: var(--text-primary);
    transition: border-color 0.2s ease;
}

.answer-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.input-error {
    color: var(--error);
    font-size: 12px;
    margin-top: -6px;
    margin-bottom: 6px;
    display: block;
    min-height: 16px;
}

.input-error.hidden {
    display: none;
}

/* ===== RESULT SECTION ===== */
.result-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.result-section.hidden {
    display: none;
}

.result-box {
    padding: 16px;
    border-radius: 8px;
    background: var(--bg-card);
    border-left: 4px solid var(--border);
}

.result-box.correct {
    border-left-color: var(--success);
    background: #f0fdf4;
}

.result-box.incorrect {
    border-left-color: var(--error);
    background: #fef2f2;
}

#resultMessage {
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 16px;
}

.result-box.correct #resultMessage {
    color: var(--success);
}

.result-box.incorrect #resultMessage {
    color: var(--error);
}

#correctAnswerDisplay {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-top: 8px;
}

.user-answer {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.correct-answer-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

/* ===== DIFFICULTY INDICATOR ===== */
.difficulty-indicator {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
}

.difficulty-indicator.easy {
    color: var(--success);
}

.difficulty-indicator.medium {
    color: var(--warning);
}

.difficulty-indicator.hard {
    color: var(--error);
}

/* ===== QUIZ FOOTER ===== */
.quiz-footer {
    padding: 12px 16px;
    text-align: center;
    color: var(--text-secondary);
    border-top: 1px solid var(--border);
}

/* ===== COMPLETION SCREEN ===== */
.complete-box {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.complete-accuracy {
    text-align: center;
    padding: 24px;
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    border-radius: 16px;
    color: white;
}

.accuracy-number {
    font-size: 48px;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 8px;
}

.accuracy-label {
    font-size: 14px;
    opacity: 0.9;
    font-weight: 500;
}

.complete-message {
    text-align: center;
    padding: 16px;
    background: #f0fdf4;
    border-radius: 8px;
    border-left: 4px solid var(--success);
}

.complete-message p {
    color: var(--success);
    font-weight: 600;
    margin: 0;
}

/* ===== LISTS ===== */
.theme-stats-list,
.hardest-words-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: var(--bg);
    border-radius: 6px;
    font-size: 14px;
}

.stat-row span:last-child {
    font-weight: 600;
    color: var(--primary);
}

.stat-row-with-progress {
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
}

.progress-bar-stat {
    width: 100%;
    height: 6px;
    background: #e5e7eb;
    border-radius: 3px;
    overflow: hidden;
}

.progress-fill-stat {
    height: 100%;
    background: linear-gradient(90deg, var(--primary) 0%, var(--secondary) 100%);
    transition: width 0.3s ease;
}

/* ===== LOADING ===== */
.loader {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 12px;
}

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

#loadingScreen {
    align-items: center;
    justify-content: center;
    gap: 12px;
    color: var(--text-secondary);
}

/* ===== RESPONSIVE ===== */
@media (min-width: 480px) {
    .app-header h1 {
        font-size: 32px;
    }

    .card-question {
        font-size: 40px;
    }

    .themes-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .stats-mini {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

@media (min-width: 768px) {
    .themes-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .quiz-content {
        justify-content: flex-start;
    }

    .card {
        margin-top: 20px;
    }
}

/* ===== LANDSCAPE MODE ===== */
@media (max-height: 600px) {
    .content {
        padding: 12px;
        gap: 12px;
    }

    .stats-mini {
        gap: 8px;
        padding: 0;
    }

    .stat-item {
        padding: 8px;
    }

    .card {
        padding: 16px;
        margin-bottom: 12px;
    }

    .card-question {
        font-size: 24px;
    }

    .quiz-content {
        gap: 12px;
        padding: 12px;
    }
}

/* ===== MODAL ===== */
.modal {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal.hidden {
    display: none;
    opacity: 0;
    z-index: -1;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1;
}

.modal-content {
    position: relative;
    z-index: 2;
    background: var(--bg-card);
    border-radius: 16px 16px 0 0;
    padding: 24px;
    width: 100%;
    max-width: 480px;
    margin-left: auto;
    margin-right: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

.modal-content h2 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.modal-content p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    flex-direction: column-reverse;
}

.modal-buttons .btn {
    flex: 1;
}

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

.btn-error:active {
    background: #dc2626;
    transform: scale(0.98);
}

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

@media (min-width: 480px) {
    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: 16px;
        margin: 0 16px;
    }

    .modal-buttons {
        flex-direction: row;
    }
}
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== PRINT ===== */
@media print {
    body {
        background: white;
    }
    .screen {
        position: static;
    }
}