/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #89f7fe 0%, #66a6ff 100%); /* 柔和的浅蓝色渐变，能衬托白字 */
    color: #ffffff;
    min-height: 100vh;
    overflow: hidden; /* 防止滚动 */
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 页面容器通用样式 */
.page {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none; /* 默认隐藏 */
    flex-direction: column;
    justify-content: center; /* 垂直居中 */
    align-items: center;
    padding: 20px;
    overflow-y: auto; /* 内容多时允许内部滚动 */
    opacity: 0;
    transition: opacity 0.3s ease;
}

.page.active {
    display: flex;
    opacity: 1;
}

/* 初始显示的页面 */
#cover-page {
    z-index: 10;
}

/* 封面页内容 */
.cover-content {
    text-align: center;
    animation: fadeIn 0.8s ease-out;
    width: 100%;
    max-width: 600px;
}

.cover-title {
    font-size: 3rem;
    font-weight: 800;
    margin-bottom: 1rem;
    text-shadow: 0 4px 6px rgba(0,0,0,0.1);
    letter-spacing: 2px;
}

.cover-description {
    font-size: 1.2rem;
    margin-bottom: 3rem;
    opacity: 0.9;
    font-weight: 300;
}

/* 圆角按钮样式 */
button {
    border: none;
    outline: none;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.2s, box-shadow 0.2s;
}

.start-button, .next-button, .submit-button, .restart-button, .review-button, .close-review-btn {
    background-color: #ffffff;
    color: #4facfe; /* 配合背景色 */
    font-size: 1.2rem;
    font-weight: bold;
    padding: 15px 50px;
    border-radius: 50px; /* 圆角 */
    box-shadow: 0 6px 20px rgba(0,0,0,0.15);
}

.start-button:active, .next-button:active, .submit-button:active, .close-review-btn:active {
    transform: scale(0.95);
}

/* 问答页布局 */
#quiz-page {
    justify-content: flex-start; /* 问答页内容较多，从顶部开始 */
    padding-top: 40px;
}

.quiz-header {
    width: 100%;
    max-width: 600px;
    margin-bottom: 20px;
}

.progress-bar {
    height: 8px;
    background: rgba(255,255,255,0.3);
    border-radius: 4px;
    margin-bottom: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #ffffff;
    width: 0%;
    transition: width 0.3s ease;
}

.question-counter {
    text-align: right;
    font-size: 0.9rem;
    opacity: 0.8;
}

.quiz-content {
    width: 100%;
    max-width: 600px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.question-title h2 {
    font-size: 1.5rem;
    margin-bottom: 30px;
    line-height: 1.4;
    font-weight: 700;
    text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* 选项容器 */
.options-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.option-item {
    width: 100%;
}

.option-button {
    width: 100%;
    padding: 18px 25px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    border-radius: 20px;
    font-size: 1.1rem;
    text-align: left;
    font-weight: 500;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    position: relative;
    overflow: hidden;
    border: 2px solid transparent; /* 预留边框空间 */
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.option-button:hover {
    background: #ffffff;
    transform: translateY(-2px);
}

.option-button.selected {
    background: #ffffff;
    color: #2196F3;
    border-color: #2196F3;
    box-shadow: 0 0 15px rgba(33, 150, 243, 0.2);
}

/* 正确/错误 高亮样式 & 动画 */
.option-button.correct {
    background: #4CAF50 !important; /* 绿色 */
    color: white !important;
    border-color: #4CAF50 !important;
    box-shadow: 0 0 20px rgba(76, 175, 80, 0.6);
    animation: pulse-green 0.5s ease-out;
}

.option-button.incorrect {
    background: #FF5252 !important; /* 红色 */
    color: white !important;
    border-color: #FF5252 !important;
    box-shadow: 0 0 20px rgba(255, 82, 82, 0.6);
    animation: shake-red 0.5s ease-in-out;
}

/* 解释区域 */
.explanation-area {
    margin-top: 25px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    padding: 20px;
    border-radius: 15px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: none; /* 默认隐藏 */
    transform-origin: top;
    animation: expandOpen 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.explanation-area.show {
    display: block;
}

.explanation-content h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: #ffffff;
    font-weight: 700;
}

.explanation-content p {
    font-size: 0.95rem;
    line-height: 1.5;
    opacity: 0.95;
}

.quiz-footer {
    width: 100%;
    max-width: 600px;
    padding: 20px 0;
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

/* 结果页 */
#result-page {
    text-align: center;
}

.result-content {
    width: 100%;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-score {
    background: rgba(255, 255, 255, 0.15);
    padding: 40px;
    border-radius: 30px;
    margin-bottom: 40px;
    backdrop-filter: blur(5px);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    animation: popIn 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.score-circle {
    display: flex;
    justify-content: center;
    align-items: baseline;
    margin-bottom: 10px;
}

#score-number {
    font-size: 5rem;
    font-weight: 800;
    line-height: 1;
}

.score-unit {
    font-size: 1.5rem;
    margin-left: 5px;
}

#score-message {
    font-size: 1.3rem;
    margin-top: 10px;
    font-weight: 500;
}

.result-stats {
    display: flex;
    justify-content: space-around;
    width: 100%;
    max-width: 400px;
    margin-bottom: 40px;
    background: rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 20px;
}

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

.stat-label {
    font-size: 0.9rem;
    opacity: 0.8;
    margin-bottom: 5px;
}

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

.result-actions {
    display: flex;
    gap: 20px;
    width: 100%;
    justify-content: center;
}

/* 解析页样式 */
#review-page {
    justify-content: flex-start;
    padding-top: 40px;
}

.review-container {
    width: 100%;
    max-width: 600px;
    padding-bottom: 40px;
}

.close-review-container {
    position: sticky;
    top: 0;
    background: inherit; /* 使用父元素背景或透明 */
    z-index: 100;
    padding-bottom: 20px;
    text-align: center;
    width: 100%;
}

.close-review-btn {
    padding: 10px 30px;
    font-size: 1rem;
}

.review-item {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(5px);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.review-question {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
    padding-bottom: 10px;
}

.review-user-answer, .review-correct-answer {
    margin-bottom: 8px;
    font-size: 0.95rem;
}

.answer-text {
    font-weight: bold;
    margin-left: 5px;
}

.answer-correct {
    color: #4CAF50; /* Green */
}

.answer-wrong {
    color: #FF5252; /* Red */
}

.review-explanation {
    margin-top: 15px;
    background: rgba(0, 0, 0, 0.1);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.review-explanation h4 {
    margin-bottom: 5px;
    opacity: 0.9;
}

/* AI 聊天机器人样式 */
.ai-entry-container {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 20px;
}

.ai-float-btn {
    position: static; /* 取消 fixed 定位 */
    width: auto; /* 宽度自适应 */
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 25px;
    padding: 0 20px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: transform 0.3s, background 0.3s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.ai-float-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

.ai-icon {
    font-size: 24px;
    margin-right: 10px;
}

.ai-text {
    color: #fff;
    font-weight: 500;
    font-size: 0.95rem;
}

.ai-chat-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 2000;
    display: none;
    justify-content: center;
    align-items: flex-end;
}

.ai-chat-modal.active {
    display: flex;
}

.ai-chat-container {
    width: 100%;
    max-width: 600px;
    height: 80vh;
    background: #fff;
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUpModal 0.3s ease-out;
}

.ai-chat-header {
    padding: 15px 20px;
    background: linear-gradient(135deg, #66a6ff 0%, #89f7fe 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.ai-chat-header h3 {
    font-size: 1.1rem;
}

.close-chat-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    box-shadow: none;
}

.ai-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 15px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    text-align: left; /* 强制左对齐 */
}

.message.ai {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.message.user {
    align-self: flex-end;
    background: #66a6ff;
    color: white;
    border-bottom-right-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.ai-chat-input-area {
    padding: 15px;
    background: #fff;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
}

.ai-chat-input {
    flex: 1;
    padding: 10px 15px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 1rem;
}

.send-chat-btn {
    padding: 10px 20px;
    background: #66a6ff;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
}

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

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

@keyframes popIn {
    0% { opacity: 0; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1); }
}

@keyframes pulse-green {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(76, 175, 80, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

@keyframes shake-red {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

@keyframes expandOpen {
    0% { opacity: 0; transform: scaleY(0); max-height: 0; }
    100% { opacity: 1; transform: scaleY(1); max-height: 500px; }
}

@keyframes slideUpModal {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

/* 响应式微调 */
@media (max-width: 360px) {
    .cover-title { font-size: 2.5rem; }
    .option-button { padding: 15px; font-size: 1rem; }
    .result-score { padding: 20px; }
    #score-number { font-size: 4rem; }
}