/* ===== BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --secondary: #06b6d4;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    overflow-x: hidden;
}

#app {
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* ===== SCREENS ===== */
.screen {
    display: none;
    flex-direction: column;
    min-height: 100vh;
    padding: 20px;
    padding-bottom: 40px;
}

.screen.active {
    display: flex;
}

/* ===== HEADER ===== */
.header {
    text-align: center;
    padding: 20px 0;
    margin-bottom: 20px;
}

.header h1 {
    font-size: 2.5em;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.header h2 {
    font-size: 1.5em;
    color: var(--text-primary);
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1em;
}

.back-btn {
    position: absolute;
    left: 20px;
    top: 20px;
    background: none;
    border: none;
    color: var(--primary);
    font-size: 1em;
    cursor: pointer;
    padding: 10px;
}

/* ===== DIFFICULTY SLIDER ===== */
.difficulty-slider-container {
    max-width: 500px;
    margin: 0 auto 25px auto;
    width: 100%;
    padding: 20px;
    background: var(--bg-card);
    border-radius: 12px;
    border: 2px solid var(--border);
}

.slider-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 1em;
    color: var(--text-primary);
}

.difficulty-value {
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--primary);
    color: white;
    font-size: 0.9em;
}

.difficulty-value.level-1 { background: #10b981; }
.difficulty-value.level-2 { background: #22c55e; }
.difficulty-value.level-3 { background: #f59e0b; }
.difficulty-value.level-4 { background: #f97316; }
.difficulty-value.level-5 { background: #ef4444; }

.difficulty-slider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--bg-hover);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.difficulty-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.difficulty-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: 3px solid white;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 0.8em;
    color: var(--text-muted);
}

/* ===== HOME MENU ===== */
.menu-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.menu-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 25px 20px;
    border-radius: 16px;
    border: 2px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.menu-btn:hover, .menu-btn:active {
    transform: translateY(-2px);
    border-color: var(--primary);
    background: var(--bg-hover);
}

.btn-icon {
    font-size: 2.5em;
    margin-bottom: 10px;
}

.btn-text {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.btn-desc {
    font-size: 0.85em;
    color: var(--text-secondary);
}

.practice-btn { border-color: var(--success); }
.practice-btn:hover { background: rgba(16, 185, 129, 0.1); }

.random-btn { border-color: var(--warning); }
.random-btn:hover { background: rgba(245, 158, 11, 0.1); }

.category-btn { border-color: var(--secondary); }
.category-btn:hover { background: rgba(6, 182, 212, 0.1); }

.history-btn { border-color: var(--primary); }
.history-btn:hover { background: rgba(79, 70, 229, 0.1); }

/* ===== STATS PREVIEW ===== */
.stats-preview {
    margin-top: 30px;
    padding: 20px;
    background: var(--bg-card);
    border-radius: 12px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
}

.stats-preview h4 {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-row {
    display: flex;
    justify-content: space-around;
    text-align: center;
}

.stat-item {
    display: flex;
    flex-direction: column;
}

.stat-item .value {
    font-size: 1.8em;
    font-weight: 700;
    color: var(--primary);
}

.stat-item .label {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-top: 5px;
}

/* ===== CATEGORY SELECT ===== */
.category-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.category-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 15px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.category-card:hover, .category-card:active {
    transform: scale(1.02);
    border-color: var(--primary);
    background: var(--bg-hover);
}

.cat-icon {
    font-size: 2em;
    margin-bottom: 8px;
}

.cat-name {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.cat-topics {
    font-size: 0.75em;
    color: var(--text-secondary);
}

/* ===== DIFFICULTY SELECTION ===== */
.difficulty-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 500px;
    margin: 0 auto;
    width: 100%;
}

.difficulty-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 25px 20px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.difficulty-card:hover, .difficulty-card:active {
    transform: scale(1.02);
}

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

.difficulty-card.easy:hover {
    background: rgba(16, 185, 129, 0.1);
}

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

.difficulty-card.medium:hover {
    background: rgba(245, 158, 11, 0.1);
}

.difficulty-card.hard {
    border-color: var(--danger);
}

.difficulty-card.hard:hover {
    background: rgba(239, 68, 68, 0.1);
}

.diff-stars {
    font-size: 1.8em;
    margin-bottom: 8px;
}

.diff-name {
    font-weight: 700;
    font-size: 1.3em;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.diff-time {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.diff-desc {
    font-size: 0.85em;
    color: var(--text-muted);
}

.difficulty-btn {
    background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%) !important;
}

/* ===== QUESTION SCREEN ===== */
.question-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.question-info {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#question-number {
    font-weight: 600;
    color: var(--text-primary);
}

.category-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75em;
    background: var(--primary);
    color: white;
}

/* ===== TIMER ===== */
.timer-container {
    position: relative;
}

.timer {
    position: relative;
    width: 70px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#timer-display {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--text-primary);
    z-index: 1;
}

.timer-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.timer-bg {
    fill: none;
    stroke: var(--bg-hover);
    stroke-width: 6;
}

.timer-progress {
    fill: none;
    stroke: var(--success);
    stroke-width: 6;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}

.timer-progress.warning {
    stroke: var(--warning);
}

.timer-progress.danger {
    stroke: var(--danger);
}

/* ===== QUESTION BODY ===== */
.question-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.difficulty-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 15px;
    font-size: 0.9em;
}

.difficulty-label {
    color: var(--text-secondary);
}

.difficulty-stars {
    letter-spacing: 2px;
}

.question-text {
    font-size: 1.3em;
    line-height: 1.6;
    color: var(--text-primary);
    padding: 25px;
    background: var(--bg-card);
    border-radius: 12px;
    margin-bottom: 25px;
    text-align: center;
}

/* ===== ANSWERS ===== */
.answers-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.answer-btn {
    display: flex;
    align-items: center;
    padding: 18px 20px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
    font-size: 1.1em;
    color: var(--text-primary);
}

.answer-btn:hover:not(.disabled) {
    border-color: var(--primary);
    background: var(--bg-hover);
}

.answer-btn:active:not(.disabled) {
    transform: scale(0.98);
}

.answer-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    font-weight: 600;
    margin-right: 15px;
    flex-shrink: 0;
}

.answer-btn.correct {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.2);
}

.answer-btn.correct .answer-letter {
    background: var(--success);
}

.answer-btn.incorrect {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.2);
}

.answer-btn.incorrect .answer-letter {
    background: var(--danger);
}

.answer-btn.disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* ===== QUESTION FOOTER ===== */
.question-footer {
    padding: 20px 0;
    display: flex;
    justify-content: flex-end;
}

.skip-btn {
    padding: 12px 25px;
    border-radius: 8px;
    border: none;
    background: var(--bg-hover);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1em;
    transition: all 0.2s ease;
}

.skip-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* ===== RESULT SCREEN ===== */
.result-content {
    max-width: 500px;
    margin: 0 auto;
    text-align: center;
    padding: 20px;
}

.result-icon {
    font-size: 5em;
    margin-bottom: 20px;
}

#result-title {
    font-size: 2em;
    margin-bottom: 10px;
}

#result-message {
    color: var(--text-secondary);
    margin-bottom: 30px;
}

.result-details {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
    text-align: left;
}

.result-question {
    font-size: 1.1em;
    color: var(--text-primary);
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border);
}

.result-details > div {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}

.result-details .label {
    color: var(--text-secondary);
}

.result-details .value {
    font-weight: 600;
    color: var(--text-primary);
}

.result-explanation {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 15px 20px;
    margin-bottom: 25px;
    text-align: left;
    color: var(--text-secondary);
    font-size: 0.95em;
    line-height: 1.5;
    border-left: 4px solid var(--primary);
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== COMPLETE SCREEN ===== */
.complete-content {
    max-width: 500px;
    margin: 0 auto;
    text-align: center;
    padding: 20px;
}

.complete-icon {
    font-size: 4em;
    margin-bottom: 15px;
}

.score-display {
    margin: 30px 0;
}

.score-circle {
    display: inline-flex;
    align-items: baseline;
    font-size: 3em;
    font-weight: 700;
    color: var(--primary);
}

.score-divider {
    margin: 0 5px;
    color: var(--text-muted);
}

#score-percentage {
    font-size: 1.5em;
    color: var(--text-secondary);
    margin-top: 10px;
}

.performance-breakdown {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 30px 0;
}

.perf-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.perf-icon {
    font-size: 1.5em;
}

.perf-stat span:nth-child(2) {
    font-size: 1.5em;
    font-weight: 700;
}

.perf-label {
    font-size: 0.85em;
    color: var(--text-secondary);
}

.avg-time {
    background: var(--bg-card);
    padding: 15px 25px;
    border-radius: 12px;
    margin-bottom: 30px;
}

.avg-time .label {
    color: var(--text-secondary);
    margin-right: 10px;
}

.complete-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== HISTORY SCREEN ===== */
.history-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--bg-card);
    padding: 20px;
    border-radius: 12px;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 2em;
    font-weight: 700;
    color: var(--primary);
    display: block;
}

.stat-card .stat-label {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-top: 5px;
}

.category-breakdown, .recent-history {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 20px;
}

.category-breakdown h3, .recent-history h3 {
    font-size: 1.1em;
    margin-bottom: 15px;
    color: var(--text-secondary);
}

#category-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cat-stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.cat-stat-row:last-child {
    border-bottom: none;
}

.cat-stat-name {
    font-weight: 500;
}

.cat-stat-accuracy {
    color: var(--success);
    font-weight: 600;
}

#history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
}

.history-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: var(--bg-hover);
    border-radius: 8px;
    gap: 12px;
}

.history-result {
    font-size: 1.5em;
}

.history-details {
    flex: 1;
}

.history-question {
    font-size: 0.9em;
    color: var(--text-primary);
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    font-size: 0.75em;
    color: var(--text-muted);
}

.history-actions {
    margin-top: 20px;
}

/* ===== BUTTONS ===== */
.btn-primary {
    padding: 15px 30px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.4);
}

.btn-secondary {
    padding: 15px 30px;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text-primary);
    font-size: 1em;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

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

.btn-danger {
    padding: 12px 25px;
    border-radius: 8px;
    border: 2px solid var(--danger);
    background: transparent;
    color: var(--danger);
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .header h1 {
        font-size: 2em;
    }

    .menu-btn {
        padding: 20px 15px;
    }

    .btn-icon {
        font-size: 2em;
    }

    .question-text {
        font-size: 1.15em;
        padding: 20px;
    }

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

    .category-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== ANIMATIONS ===== */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.pulse {
    animation: pulse 0.5s ease-in-out;
}

/* ===== EMPTY STATES ===== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3em;
    margin-bottom: 15px;
}

.empty-state-text {
    font-size: 1em;
}
