/* ========================================
   基础样式设置
   ======================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #7c3aed;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --dark-bg: #1e293b;
    --light-bg: #f8fafc;
    --card-bg: #ffffff;
    --text-dark: #0f172a;
    --text-light: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-dark);
}

.hidden {
    display: none !important;
}

/* ========================================
   弹窗样式
   ======================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--card-bg);
    padding: 40px;
    border-radius: 20px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-xl);
    animation: modalSlideIn 0.3s ease-out;
}

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

.modal-content h2 {
    color: var(--primary-color);
    font-size: 28px;
    margin-bottom: 10px;
    text-align: center;
}

.modal-content h3 {
    color: var(--text-light);
    font-size: 20px;
    margin-bottom: 20px;
    text-align: center;
    font-weight: normal;
}

.modal-content p {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 10px;
}

/* ========================================
   表单样式
   ======================================== */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-dark);
}

.form-group select,
.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
}

.form-group select:focus,
.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* ========================================
   按钮样式
   ======================================== */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 14px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--light-bg);
    color: var(--text-dark);
    border: 2px solid var(--border-color);
}

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

.btn-large {
    padding: 16px 32px;
    font-size: 18px;
    margin-top: 20px;
}

.btn-exit {
    padding: 8px 16px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-left: 15px;
}

.btn-exit:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

.btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.phase2-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
}

/* ========================================
   首页按钮组
   ======================================== */
.home-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.home-buttons .btn-large {
    width: 100%;
    margin-top: 0;
}

/* ========================================
   游戏容器
   ======================================== */
#gameContainer {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

.game-header {
    background: var(--card-bg);
    padding: 20px 30px;
    border-radius: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    box-shadow: var(--shadow-md);
}

.student-info {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
}

.attempts-counter {
    font-size: 14px;
    color: var(--text-light);
    margin-top: 5px;
}

.game-title h1 {
    font-size: 32px;
    color: var(--primary-color);
    margin-bottom: 5px;
    text-align: center;
}

.game-title .theme {
    text-align: center;
    color: var(--text-light);
    font-size: 16px;
}

.score-display {
    font-size: 24px;
    font-weight: 700;
    color: var(--success-color);
}

/* ========================================
   游戏阶段样式
   ======================================== */
.game-phase {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
}

.phase-header {
    text-align: center;
    margin-bottom: 30px;
}

.phase-header h2 {
    font-size: 28px;
    color: var(--primary-color);
    margin-bottom: 10px;
}

.phase-header p {
    color: var(--text-light);
    font-size: 16px;
    margin-bottom: 20px;
}

/* ========================================
   计时器样式
   ======================================== */
.timer-container {
    max-width: 300px;
    margin: 0 auto 20px;
}

.timer {
    font-size: 48px;
    font-weight: 700;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 10px;
}

.timer.warning {
    color: var(--warning-color);
    animation: pulse 1s infinite;
}

.timer.danger {
    color: var(--danger-color);
    animation: pulse 0.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

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

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

/* ========================================
   选择计数器
   ======================================== */
.selection-counter {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-dark);
    margin-top: 15px;
}

.selection-counter span {
    color: var(--primary-color);
}

.translation-counter {
    font-size: 18px;
    font-weight: 600;
    color: var(--secondary-color);
    margin-top: 10px;
    padding: 10px 20px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 8px;
    display: inline-block;
}

.translation-counter span {
    color: #f59e0b;
    font-size: 20px;
}

/* ========================================
   句子显示框
   ======================================== */
.sentence-display-box {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    padding: 20px;
    margin: 20px 0;
    box-shadow: var(--shadow-md);
}

.sentence-display-box h3 {
    color: var(--primary-color);
    font-size: 18px;
    margin-bottom: 12px;
}

.sentence-text {
    font-size: 16px;
    line-height: 1.8;
    color: var(--text-dark);
    font-weight: 500;
    text-align: left;
    margin: 0;
}

/* ========================================
   卡片容器
   ======================================== */
.cards-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.word-card {
    background: var(--light-bg);
    padding: 30px 20px;
    border-radius: 12px;
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s ease;
    box-shadow: var(--shadow-sm);
    position: relative;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.word-card .word-text {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    line-height: 1.4;
}

.word-card .translation-text {
    font-size: 16px;
    color: #f59e0b;
    font-weight: 500;
    margin-top: 6px;
    display: block;
}

.word-card .translate-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(59, 130, 246, 0.1);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.word-card .translate-btn:hover {
    background: rgba(59, 130, 246, 0.25);
    transform: scale(1.15);
}

.word-card.translation-shown {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-color: #f59e0b;
}

.word-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
}

.word-card.selected {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.word-card.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ========================================
   第二阶段 - 已选单词显示
   ======================================== */
.selected-words-display {
    margin-bottom: 30px;
}

.selected-words-display h3 {
    font-size: 20px;
    color: var(--text-dark);
    margin-bottom: 15px;
}

#selectedWordsList {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.selected-word-badge {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: 600;
}

/* ========================================
   句子输入区域
   ======================================== */
.sentence-input-container {
    margin-bottom: 20px;
}

#sentenceInput {
    width: 100%;
    padding: 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    resize: vertical;
    transition: all 0.3s ease;
}

#sentenceInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.word-count {
    text-align: right;
    color: var(--text-light);
    font-size: 14px;
    margin-top: 8px;
}

.speech-instructions {
    margin: 30px 0;
}

.instruction-card {
    background: var(--light-bg);
    padding: 24px;
    border-radius: 12px;
    border-left: 4px solid var(--primary-color);
}

.instruction-card h3 {
    color: var(--primary-color);
    font-size: 20px;
    margin-bottom: 15px;
}

.instruction-card ul {
    list-style: none;
    padding: 0;
}

.instruction-card li {
    padding: 8px 0;
    color: var(--text-dark);
    line-height: 1.6;
}

.instruction-card li:before {
    content: "• ";
    color: var(--primary-color);
    font-weight: bold;
    margin-right: 8px;
}

.score-item.info {
    color: var(--primary-color);
    font-weight: 600;
}

/* ========================================
   结果界面
   ======================================== */
.result-container {
    text-align: center;
    max-width: 600px;
    margin: 0 auto;
}

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

.result-icon.success::before {
    content: "✓";
    color: var(--success-color);
}

.result-icon.failure::before {
    content: "✗";
    color: var(--danger-color);
}

#resultTitle {
    font-size: 36px;
    margin-bottom: 15px;
}

#resultTitle.success {
    color: var(--success-color);
}

#resultTitle.failure {
    color: var(--danger-color);
}

.result-message {
    font-size: 18px;
    color: var(--text-light);
    margin-bottom: 30px;
}

/* ========================================
   分数明细
   ======================================== */
.score-breakdown {
    background: var(--light-bg);
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 30px;
}

.score-breakdown h3 {
    font-size: 20px;
    color: var(--text-dark);
    margin-bottom: 20px;
}

.score-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 16px;
}

.score-item:last-child {
    border-bottom: none;
}

.score-item.total {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-color);
    margin-top: 10px;
}

.score-item.pending {
    color: var(--text-light);
    font-style: italic;
}

/* ========================================
   结果操作按钮
   ======================================== */
.result-actions {
    display: flex;
    gap: 15px;
}

.result-actions button {
    flex: 1;
}

/* ========================================
   排行榜
   ======================================== */
.leaderboard-content {
    max-width: 800px;
    max-height: 80vh;
    overflow-y: auto;
}

.close-btn {
    float: right;
    font-size: 32px;
    font-weight: bold;
    color: var(--text-light);
    cursor: pointer;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-dark);
}

.leaderboard-table {
    width: 100%;
    margin-top: 20px;
}

.leaderboard-row {
    display: flex;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

.leaderboard-row:hover {
    background: var(--light-bg);
}

.leaderboard-row.header {
    font-weight: 700;
    color: var(--primary-color);
    background: var(--light-bg);
}

.leaderboard-row.top-1 {
    background: linear-gradient(90deg, rgba(255,215,0,0.2), transparent);
}

.leaderboard-row.top-2 {
    background: linear-gradient(90deg, rgba(192,192,192,0.2), transparent);
}

.leaderboard-row.top-3 {
    background: linear-gradient(90deg, rgba(205,127,50,0.2), transparent);
}

.rank {
    flex: 0 0 60px;
    font-weight: 700;
}

.student {
    flex: 1;
}

.score {
    flex: 0 0 100px;
    text-align: right;
    font-weight: 700;
    color: var(--success-color);
}

/* ========================================
   加载动画
   ======================================== */
#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loadingOverlay p {
    color: white;
    font-size: 18px;
    margin-top: 20px;
}

/* ========================================
   响应式设计
   ======================================== */
@media (max-width: 768px) {
    .game-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .game-title h1 {
        font-size: 24px;
    }
    
    .cards-container {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 15px;
    }
    
    .word-card {
        padding: 20px 15px;
        font-size: 18px;
    }
    
    .result-actions {
        flex-direction: column;
    }
    
    .modal-content {
        padding: 30px 20px;
    }
}

@media (max-width: 480px) {
    #gameContainer {
        padding: 10px;
    }
    
    .cards-container {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .timer {
        font-size: 36px;
    }
}
