/* 기본 설정 및 CSS 변수 - 다크모드 호환 */
:root {
    /* 라이트 테마 색상 */
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --success-dark: #059669;
    --danger-color: #ef4444;
    --danger-dark: #dc2626;
    --warning-color: #f59e0b;
    --warning-dark: #d97706;
    
    /* 배경 및 표면 색상 */
    --background-color: #f8fafc;
    --background-secondary: #f1f5f9;
    --surface-color: #ffffff;
    --surface-hover: #f8fafc;
    
    /* 텍스트 색상 */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-tertiary: #94a3b8;
    --text-inverse: #ffffff;
    
    /* 테두리 및 구분선 */
    --border-color: #e2e8f0;
    --border-color-light: #f1f5f9;
    --border-color-dark: #cbd5e1;
    
    /* 그림자 */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    
    /* 기타 */
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --transition: all 0.2s ease-in-out;
}

/* 다크 테마 색상 (시스템 다크모드 감지) */
@media (prefers-color-scheme: dark) {
    :root {
        /* 배경 및 표면 색상 */
        --background-color: #0f172a;
        --background-secondary: #1e293b;
        --surface-color: #1e293b;
        --surface-hover: #334155;
        
        /* 텍스트 색상 */
        --text-primary: #f1f5f9;
        --text-secondary: #cbd5e1;
        --text-tertiary: #94a3b8;
        --text-inverse: #1e293b;
        
        /* 테두리 및 구분선 */
        --border-color: #334155;
        --border-color-light: #475569;
        --border-color-dark: #64748b;
        
        /* 기본 색상 다크모드 조정 */
        --primary-color: #3b82f6;
        --primary-dark: #2563eb;
        --success-color: #22c55e;
        --danger-color: #f87171;
        --warning-color: #fbbf24;
        
        /* 그림자 (다크모드용) */
        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
        --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.2);
    }
}

/* 강제 다크모드 클래스 (수동 토글용) */
.dark-mode {
    --background-color: #0f172a;
    --background-secondary: #1e293b;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    --text-inverse: #1e293b;
    --border-color: #334155;
    --border-color-light: #475569;
    --border-color-dark: #64748b;
    --primary-color: #3b82f6;
    --primary-dark: #2563eb;
    --success-color: #22c55e;
    --danger-color: #f87171;
    --warning-color: #fbbf24;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.2);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.3), 0 4px 6px -4px rgb(0 0 0 / 0.2);
}

/* 기본 스타일 초기화 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* 공통 컨테이너 */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 화면 전환 */
.screen {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.screen.active {
    display: block;
}

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

/* 로딩 화면 */
.loading-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100vh;
    text-align: center;
    padding: 20px;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 24px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-progress {
    width: 200px;
    height: 4px;
    background-color: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 20px;
}

.loading-progress .progress-bar {
    width: 0%;
    height: 100%;
    background-color: var(--primary-color);
    animation: loading 2s ease-in-out infinite;
}

@keyframes loading {
    0% { width: 0%; }
    50% { width: 70%; }
    100% { width: 100%; }
}

/* 헤더 스타일 */
.header {
    text-align: center;
    margin-bottom: 40px;
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 8px;
}

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

/* 퀴즈 정보 카드 */
.quiz-info {
    display: grid;
    gap: 16px;
    margin-bottom: 40px;
}

.info-card {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 20px;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

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

.info-icon {
    font-size: 2rem;
    margin-right: 16px;
    flex-shrink: 0;
}

.info-content h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.info-content p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* 버튼 스타일 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--border-radius-sm);
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    min-height: 48px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

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

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--surface-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--background-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-large {
    padding: 16px 32px;
    font-size: 1.1rem;
    width: 100%;
}

/* 퀴즈 헤더 */
.quiz-header {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.progress-container {
    margin-bottom: 16px;
}

.progress-bar-container {
    width: 100%;
    height: 8px;
    background-color: var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.3s ease;
    border-radius: 4px;
}

.progress-text {
    text-align: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.score-container {
    display: flex;
    justify-content: space-around;
    gap: 16px;
}

.score-item {
    text-align: center;
    flex: 1;
}

.score-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.score-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* 문제 영역 */
.question-container {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    flex-grow: 1;
}

.question-number {
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 16px;
}

.question-text {
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 24px;
    color: var(--text-primary);
    font-weight: 500;
}

.options-container {
    display: grid;
    gap: 12px;
}

.option {
    background: var(--surface-color);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    padding: 16px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.option:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.option.selected {
    border-color: var(--primary-color);
    background-color: var(--surface-hover);
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

.option-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--border-color);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 600;
    flex-shrink: 0;
    transition: var(--transition);
}

.option.selected .option-number {
    background-color: var(--primary-color);
    color: var(--text-inverse);
}

.option-text {
    flex-grow: 1;
    line-height: 1.5;
}

/* 액션 버튼 영역 */
.action-buttons {
    display: flex;
    gap: 12px;
    margin-top: auto;
}

/* 결과 화면 */
.result-container {
    text-align: center;
    padding: 40px 20px;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 24px;
}

.result-message {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 32px;
}

.result-message.correct {
    color: var(--success-color);
}

.result-message.incorrect {
    color: var(--danger-color);
}

.answer-details {
    text-align: left;
    margin-bottom: 32px;
}

.answer-section {
    margin-bottom: 20px;
}

.answer-section h4 {
    font-size: 1rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.answer-text {
    background: var(--background-color);
    border-radius: var(--border-radius-sm);
    padding: 12px 16px;
    border-left: 4px solid var(--border-color);
}

.answer-text.correct {
    border-left-color: var(--success-color);
    background-color: var(--background-secondary);
    color: var(--text-primary);
}

/* 해설 화면 */
.explanation-container {
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.explanation-header h3 {
    color: var(--primary-color);
    margin-bottom: 24px;
    text-align: center;
}

.explanation-section {
    margin-bottom: 24px;
}

.explanation-section h4 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.explanation-text {
    background: var(--background-color);
    border-radius: var(--border-radius-sm);
    padding: 16px;
    line-height: 1.7;
    border-left: 4px solid var(--primary-color);
}

.reference-text {
    background: var(--background-secondary);
    border: 2px solid var(--warning-color);
    border-radius: var(--border-radius-sm);
    padding: 12px 16px;
    font-weight: 600;
    color: var(--text-primary);
    border-left: 4px solid var(--warning-color);
}

/* 최종 결과 화면 */
.final-result-container {
    text-align: center;
    background: var(--surface-color);
    border-radius: var(--border-radius);
    padding: 32px 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.result-header h2 {
    color: var(--primary-color);
    margin-bottom: 24px;
    font-size: 2rem;
}

.score-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    font-size: 2rem;
    font-weight: 700;
    color: white;
    margin-bottom: 32px;
    box-shadow: var(--shadow-lg);
}

.score-badge.excellent { background: linear-gradient(135deg, #10b981, #059669); }
.score-badge.good { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.score-badge.average { background: linear-gradient(135deg, #f59e0b, #d97706); }
.score-badge.poor { background: linear-gradient(135deg, #ef4444, #dc2626); }

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    margin-bottom: 32px;
}

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

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
    display: block;
    margin-bottom: 4px;
}

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

.performance-evaluation {
    margin-bottom: 32px;
}

.performance-grade {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.performance-message {
    color: var(--text-secondary);
    line-height: 1.6;
}

.wrong-answers {
    text-align: left;
    background: var(--background-color);
    border-radius: var(--border-radius-sm);
    padding: 20px;
    margin-bottom: 32px;
}

.wrong-answers h4 {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.wrong-answers-list {
    display: grid;
    gap: 12px;
}

.wrong-answer-item {
    background: var(--surface-color);
    border-radius: var(--border-radius-sm);
    padding: 12px;
    border-left: 4px solid var(--danger-color);
    font-size: 0.9rem;
}

.footer-info {
    text-align: center;
    margin-top: 32px;
    color: var(--text-secondary);
}

.footer-info p {
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.footer-message {
    margin-top: 32px;
    padding: 20px;
    background: var(--background-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
}

.footer-message p {
    margin-bottom: 8px;
}

/* 반응형 디자인 */
@media (max-width: 480px) {
    .container {
        padding: 16px;
    }
    
    .header h1 {
        font-size: 1.75rem;
    }
    
    .info-card {
        padding: 16px;
    }
    
    .question-container {
        padding: 20px;
    }
    
    .result-stats {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .score-badge {
        width: 100px;
        height: 100px;
        font-size: 1.5rem;
    }
    
    .action-buttons {
        flex-direction: column;
    }
}

/* 다크 모드 지원 (시스템 설정 기반) */
@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #0f172a;
        --surface-color: #1e293b;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --border-color: #334155;
    }
}

/* 접근성 향상 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* 터치 디바이스 최적화 */
@media (hover: none) and (pointer: coarse) {
    .btn:hover {
        transform: none;
    }
    
    .option:hover {
        border-color: var(--border-color);
    }
    
    .info-card:hover {
        transform: none;
    }
}

/* ===========================
   다크모드 가독성 개선 추가 스타일
   =========================== */

/* 선택지 개선된 스타일 */
.option {
    color: var(--text-primary) !important;
    transition: all 0.2s ease-in-out;
}

.option:hover {
    background: var(--surface-hover);
    transform: translateY(-1px);
}

.option.selected {
    background: var(--surface-hover);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.option.correct {
    background: var(--background-secondary) !important;
    border-color: var(--success-color) !important;
    color: var(--text-primary) !important;
}

.option.correct .option-number {
    background-color: var(--success-color) !important;
    color: var(--text-inverse) !important;
}

.option.incorrect {
    background: var(--background-secondary) !important;
    border-color: var(--danger-color) !important;
    color: var(--text-primary) !important;
    opacity: 0.7;
}

.option.incorrect .option-number {
    background-color: var(--danger-color) !important;
    color: var(--text-inverse) !important;
}

/* 해설 섹션 개선 */
.explanation-container {
    background: var(--surface-color) !important;
    color: var(--text-primary) !important;
}

.explanation-text {
    background: var(--background-secondary) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border-color-light);
}

.explanation-section h4 {
    color: var(--text-primary) !important;
    font-weight: 600;
}

/* 결과 메시지 개선 */
.result-message {
    color: var(--text-primary) !important;
    font-weight: 600;
}

.result-message.correct {
    color: var(--success-color) !important;
}

.result-message.incorrect {
    color: var(--danger-color) !important;
}

/* 정답 텍스트 개선 */
.answer-text {
    background: var(--background-secondary) !important;
    color: var(--text-primary) !important;
}

.answer-text.correct {
    background: var(--background-secondary) !important;
    color: var(--text-primary) !important;
}

/* 버튼 텍스트 명확성 개선 */
.btn-primary {
    color: var(--text-inverse) !important;
    background: var(--primary-color) !important;
}

.btn-primary:hover {
    background: var(--primary-dark) !important;
    color: var(--text-inverse) !important;
}

.btn-secondary {
    color: var(--text-primary) !important;
    background: var(--surface-color) !important;
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--surface-hover) !important;
    color: var(--text-primary) !important;
}

/* 강제 텍스트 명도 보장 */
.option-text,
.explanation-text p,
.explanation-text,
.answer-text p,
.answer-text,
.reference-text {
    color: var(--text-primary) !important;
    background-color: transparent !important;
}

/* 참고자료 섹션 개선 */
.reference-text {
    background: var(--background-secondary) !important;
    border: 2px solid var(--warning-color) !important;
    color: var(--text-primary) !important;
    font-weight: 600;
}

/* 선택 상태의 대비 개선 */
.option.selected .option-text {
    color: var(--text-primary) !important;
    font-weight: 500;
}

/* 다크모드 전용 추가 대비 */
@media (prefers-color-scheme: dark) {
    .option.selected {
        background: rgba(59, 130, 246, 0.1) !important;
        border-color: var(--primary-color);
    }
    
    .option.correct {
        background: rgba(34, 197, 94, 0.1) !important;
    }
    
    .option.incorrect {
        background: rgba(248, 113, 113, 0.1) !important;
    }
    
    .explanation-text {
        background: var(--background-secondary) !important;
        border-color: var(--border-color);
    }
    
    .answer-text.correct {
        background: rgba(34, 197, 94, 0.1) !important;
    }
    
    .reference-text {
        background: var(--background-secondary) !important;
        border-color: var(--warning-color) !important;
        color: var(--text-primary) !important;
    }
}

/* 강제 다크모드 클래스에서도 동일하게 적용 */
.dark-mode .option.selected {
    background: rgba(59, 130, 246, 0.1) !important;
}

.dark-mode .option.correct {
    background: rgba(34, 197, 94, 0.1) !important;
}

.dark-mode .option.incorrect {
    background: rgba(248, 113, 113, 0.1) !important;
}

.dark-mode .explanation-text {
    background: var(--background-secondary) !important;
}

.dark-mode .answer-text.correct {
    background: rgba(34, 197, 94, 0.1) !important;
}

.dark-mode .reference-text {
    background: var(--background-secondary) !important;
    border-color: var(--warning-color) !important;
    color: var(--text-primary) !important;
}

/* 브라우저별 호환성 개선 */
.option *,
.explanation-container *,
.answer-text * {
    color: inherit !important;
}

/* 접근성 개선 - 포커스 스타일 */
.option:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

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

/* 안전장치: 모든 텍스트 요소에 강제 색상 적용 */
body, body * {
    color: var(--text-primary);
}

/* 하지만 이미 색상이 지정된 요소들은 유지 */
.text-primary { color: var(--text-primary) !important; }
.text-secondary { color: var(--text-secondary) !important; }
.text-success { color: var(--success-color) !important; }
.text-danger { color: var(--danger-color) !important; }
.text-warning { color: var(--warning-color) !important; }

