/* 全局樣式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Microsoft YaHei', '微軟正黑體', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.container {
    max-width: 900px;
    width: 100%;
}

/* 標題區域 */
header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.subtitle {
    font-size: 1.2rem;
    opacity: 0.9;
}

/* 區塊樣式 */
.section {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    animation: fadeIn 0.5s ease-in;
}

.section h2 {
    text-align: center;
    color: #667eea;
    font-size: 2rem;
    margin-bottom: 30px;
}

.section h3 {
    color: #667eea;
    font-size: 1.3rem;
    margin: 30px 0 20px 0;
    padding-bottom: 10px;
    border-bottom: 2px solid #e0e0e0;
}

/* 設定區域 */
.setup-group {
    margin-bottom: 30px;
}

.setup-label {
    display: block;
    font-size: 1.2rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 15px;
}

.time-input {
    width: 100%;
    max-width: 300px;
    padding: 15px 20px;
    font-size: 1.5rem;
    border: 3px solid #667eea;
    border-radius: 10px;
    text-align: center;
    outline: none;
    transition: border-color 0.3s;
}

.time-input:focus {
    border-color: #764ba2;
}

/* 移除數字輸入框的箭頭 */
.time-input::-webkit-outer-spin-button,
.time-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* 難度選擇按鈕 */
.level-buttons {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.level-btn {
    flex: 1;
    min-width: 180px;
    padding: 25px 20px;
    background: #f5f5f5;
    border: 3px solid #e0e0e0;
    border-radius: 15px;
    color: #666;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.level-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.level-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-color: #667eea;
    color: white;
    box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
}

.level-icon {
    font-size: 2.5rem;
}

.level-title {
    font-size: 1.3rem;
    font-weight: bold;
}

.level-desc {
    font-size: 0.9rem;
    opacity: 0.9;
}

/* 測驗區域 */
.test-header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 15px;
    color: white;
    flex-wrap: wrap;
    gap: 15px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.timer-display {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 1.2rem;
}

.timer-value {
    font-size: 2.5rem;
    font-weight: bold;
    min-width: 60px;
    text-align: center;
}

.timer-value.warning {
    color: #ff6b6b;
    animation: pulse 1s infinite;
}

.timer-value.overtime {
    color: #ff3838;
    font-weight: bold;
    animation: pulse 1s infinite;
}

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

.progress-display {
    font-size: 1.2rem;
}

/* 題目容器 */
.questions-container {
    margin-bottom: 30px;
}

/* 題目項目 */
.question-item {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
    margin-bottom: 15px;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 12px;
    transition: transform 0.2s;
}

.question-item:hover {
    transform: translateX(5px);
}

.question-number {
    font-size: 1.5rem;
    font-weight: bold;
    color: #667eea;
    min-width: 40px;
}

.question-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.question-math {
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
    min-width: 150px;
}

.answer-input {
    width: 120px;
    padding: 10px 15px;
    font-size: 1.3rem;
    border: 3px solid #667eea;
    border-radius: 8px;
    text-align: center;
    outline: none;
    transition: border-color 0.3s;
}

.answer-input:focus {
    border-color: #764ba2;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.answer-input:disabled {
    background: #e0e0e0;
    cursor: not-allowed;
}

.answer-input::-webkit-outer-spin-button,
.answer-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* 按鈕樣式 */
.btn-large {
    width: 100%;
    padding: 18px 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.3rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
}

.btn-large:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
}

.btn-large:active {
    transform: translateY(0);
}

.btn-large:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* 時間到提示 */
.timeout-alert {
    text-align: center;
    padding: 15px;
    margin-bottom: 20px;
    background: #fff3cd;
    color: #856404;
    border: 2px solid #ffc107;
    border-radius: 10px;
    font-size: 1.2rem;
    font-weight: bold;
    animation: slideIn 0.5s ease-out;
}

/* 分數卡片 */
.score-card {
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    border-radius: 15px;
    padding: 40px;
    margin-bottom: 30px;
    text-align: center;
}

.score-card.perfect {
    background: linear-gradient(135deg, #ffd89b 0%, #19547b 100%);
    animation: celebrate 1s ease-in-out;
}

.score-card.excellent {
    background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
}

@keyframes celebrate {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(1.05) rotate(2deg); }
    75% { transform: scale(1.05) rotate(-2deg); }
}

.score-main {
    margin-bottom: 30px;
}

.score-value {
    font-size: 5rem;
    font-weight: bold;
    color: #667eea;
    margin-bottom: 15px;
}

.score-card.perfect .score-value {
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.score-unit {
    font-size: 2.5rem;
}

.score-message {
    font-size: 1.8rem;
    color: #333;
    font-weight: bold;
}

.score-card.perfect .score-message {
    color: #fff;
}

.score-stats {
    display: flex;
    justify-content: space-around;
    padding-top: 30px;
    border-top: 2px solid rgba(255, 255, 255, 0.3);
    flex-wrap: wrap;
    gap: 20px;
}

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

.stat-label {
    font-size: 1rem;
    color: #666;
    display: block;
    margin-bottom: 8px;
}

.score-card.perfect .stat-label {
    color: rgba(255, 255, 255, 0.9);
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
}

.stat-value.correct {
    color: #4CAF50;
}

.stat-value.wrong {
    color: #f44336;
}

.score-card.perfect .stat-value {
    color: #fff;
}

/* 時間資訊 */
.time-info {
    margin-top: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.time-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.1rem;
}

.time-label {
    color: #666;
    font-weight: 600;
}

.time-value {
    color: #333;
    font-weight: bold;
    font-size: 1.2rem;
}

.time-value.overtime-text {
    color: #f44336;
}

.overtime-item {
    border-top: 2px solid rgba(244, 67, 54, 0.2);
    padding-top: 12px;
}

.score-card.perfect .time-info {
    background: rgba(255, 255, 255, 0.3);
}

.score-card.perfect .time-label,
.score-card.perfect .time-value {
    color: #fff;
}

.score-card.perfect .time-value.overtime-text {
    color: #ffeb3b;
}

/* 分數明細 */
.score-breakdown {
    margin-top: 20px;
    padding: 20px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
}

.breakdown-item.penalty {
    color: #f44336;
}

.breakdown-item.final {
    border-top: 2px solid #667eea;
    padding-top: 10px;
    margin-top: 5px;
    font-size: 1.2rem;
    font-weight: bold;
}

.breakdown-label {
    color: #666;
}

.breakdown-value {
    color: #333;
    font-weight: bold;
}

.breakdown-item.final .breakdown-value {
    color: #667eea;
    font-size: 1.4rem;
}

.score-card.perfect .score-breakdown {
    background: rgba(255, 255, 255, 0.3);
}

.score-card.perfect .breakdown-label,
.score-card.perfect .breakdown-value {
    color: #fff;
}

/* 詳細結果 */
.results-detail {
    margin-top: 30px;
}

.result-item {
    display: flex;
    gap: 15px;
    padding: 20px;
    margin-bottom: 15px;
    border-radius: 12px;
    transition: transform 0.2s;
}

.result-item:hover {
    transform: translateX(5px);
}

.result-item.correct {
    background: #d4edda;
    border-left: 5px solid #4CAF50;
}

.result-item.incorrect {
    background: #f8d7da;
    border-left: 5px solid #f44336;
}

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

.result-icon {
    font-size: 2rem;
}

.result-number {
    font-size: 0.9rem;
    color: #666;
    font-weight: bold;
}

.result-content {
    flex: 1;
}

.result-question {
    font-size: 1.3rem;
    font-weight: bold;
    color: #333;
    margin-bottom: 10px;
}

.result-answers {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 1rem;
}

.user-answer {
    color: #333;
}

.correct-answer {
    color: #d32f2f;
}

.result-answers strong {
    font-size: 1.2rem;
}

/* 隱藏類 */
.hidden {
    display: none !important;
}

/* 動畫 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

/* 響應式設計 */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .section {
        padding: 20px;
    }

    .section h2 {
        font-size: 1.5rem;
    }

    .test-header {
        flex-direction: column;
        text-align: center;
    }

    .timer-value {
        font-size: 2rem;
    }

    .level-btn {
        min-width: 140px;
        padding: 20px 15px;
    }

    .level-icon {
        font-size: 2rem;
    }

    .level-title {
        font-size: 1.1rem;
    }

    .question-item {
        flex-direction: column;
        align-items: flex-start;
    }

    .question-math {
        font-size: 1.2rem;
        min-width: auto;
    }

    .answer-input {
        width: 100%;
        max-width: 150px;
    }

    .score-value {
        font-size: 3.5rem;
    }

    .score-message {
        font-size: 1.3rem;
    }

    .btn-large {
        font-size: 1.1rem;
        padding: 15px 30px;
    }

    .result-item {
        flex-direction: column;
        gap: 10px;
    }

    .result-header {
        flex-direction: row;
        justify-content: flex-start;
    }
}
