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

:root {
    /* 主色调 - 蓝色和绿色 */
    --primary-color: #2196f3;
    --primary-light: #4caf50;
    --primary-dark: #1976d2;
    --primary-gradient: var(--primary-color);
    
    /* 辅助色 */
    --success-color: #4caf50;
    --warning-color: #ff9800;
    --error-color: #f44336;
    --info-color: #2196f3;
    
    /* 中性色 */
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --text-light: #95a5a6;
    --bg-primary: #f8f9fa;
    --bg-white: #ffffff;
    --bg-dark: #343a40;
    
    /* 边框和阴影 */
    --border-color: #e8f0fe;
    --border-radius: 12px;
    --border-radius-lg: 20px;
    --box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --box-shadow-hover: 0 8px 30px rgba(0, 0, 0, 0.12);
    --box-shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.15);
    
    /* 过渡效果 */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: linear-gradient(135deg, #f6f9fc 0%, #eef2f6 100%);
    min-height: 100vh;
}

/* ==================== 主容器 ==================== */
.main-container {
    max-width: 900px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* ==================== 卡片样式 ==================== */
.card {
    background: var(--bg-white);
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow-lg);
    overflow: hidden;
    transition: var(--transition-normal);
}

.card:hover {
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
}

.card-header {
    background: var(--primary-gradient);
    color: white;
    padding: 1.75rem 2rem;
    text-align: center;
}

.card-title {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

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

.card-body {
    padding: 2rem;
}

/* ==================== 表单样式 ==================== */
.user-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-input,
.form-select {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: var(--bg-white);
}

.form-input:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
}

/* ==================== 按钮样式 ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.75rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-normal);
    text-decoration: none;
    user-select: none;
}

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

.btn-primary {
    background: #2196f3;
    color: white;
}

.btn-primary:hover {
    background: #1976d2;
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-hover);
}

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

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

.btn-secondary:hover {
    background: #43a047;
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-hover);
}

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.btn-outline:hover {
    border-color: #2196f3;
    color: #2196f3;
    background: var(--bg-primary);
    transform: translateY(-2px);
    box-shadow: var(--box-shadow);
}

.btn-text {
    background: transparent;
    color: var(--error-color);
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

.btn-text:hover {
    background: rgba(244, 67, 54, 0.1);
}

.btn-danger:hover {
    background: var(--error-color);
    color: white;
}

.btn-large {
    width: 100%;
    padding: 1.125rem 2rem;
    font-size: 1.125rem;
}

/* ==================== 按钮组 ==================== */
.btn-group {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* 移动端：垂直排列 */
@media (max-width: 768px) {
    .btn-group {
        flex-direction: column;
    }

    .btn-large {
        width: 100%;
    }
}

/* 桌面端：水平排列 */
@media (min-width: 769px) {
    .btn-group {
        flex-direction: row;
    }

    .btn-large {
        flex: 1;
        width: auto;
        min-width: 0;
    }
}

/* ==================== 训练说明 ==================== */
.instructions {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-radius: var(--border-radius);
    padding: 1.5rem;
    border-left: 4px solid #2196f3;
    margin-top: 1.5rem;
}

.instructions-title {
    color: var(--text-primary);
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 1rem;
}

.instructions-list {
    list-style: none;
    padding-left: 0;
}

.instructions-list li {
    position: relative;
    padding-left: 2rem;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.instructions-list li:last-child {
    margin-bottom: 0;
}

.instructions-list li::before {
    content: '✓';
    position: absolute;
    left: 0;
    color: #2196f3;
    font-weight: bold;
    font-size: 1.2em;
}

/* ==================== 本地存储提示 ==================== */
.local-tip {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
    background: linear-gradient(135deg, #fff8e1 0%, #fff3cd 100%);
    border-radius: var(--border-radius);
    padding: 1.25rem;
    margin-top: 1.5rem;
    border-left: 4px solid #ffc107;
}

.tip-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

.tip-content {
    flex: 1;
}

.tip-title {
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.tip-text {
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.6;
}

/* ==================== 游戏卡片 ==================== */
.game-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
    padding: 1.5rem 2rem;
    background: var(--bg-primary);
    border-radius: 8px;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.control-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.control-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* ==================== 游戏区域 ==================== */
.game-area {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    min-height: 400px;
}

.number-display-container {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-white);
    border-radius: 12px;
    margin-bottom: 2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    padding: 2rem;
}

.number-display {
    font-size: 4rem;
    font-weight: bold;
    letter-spacing: 15px;
    color: var(--text-primary);
    text-align: center;
}

.number-display.loading {
    font-size: 1.5rem;
    letter-spacing: normal;
    color: var(--text-light);
}

.options-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
}

.options-container.hidden {
    display: none;
}

.option-countdown {
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 600;
    background: #fff3cd;
    border: 2px solid #ffc107;
    border-radius: 8px;
    color: #856404;
    text-align: center;
    margin-bottom: 1rem;
    box-shadow: var(--box-shadow);
}

.option-btn {
    padding: 2rem;
    font-size: 2rem;
    font-weight: bold;
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
    box-shadow: var(--box-shadow);
    text-align: center;
}

.option-btn:hover {
    background: #f0f0f0;
    border-color: #2196f3;
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-hover);
}

.option-btn.correct {
    background: #4CAF50;
    color: white;
    border-color: #388E3C;
}

.option-btn.incorrect {
    background: #f44336;
    color: white;
    border-color: #d32f2f;
}

/* ==================== 结果卡片 ==================== */
.result-header {
    text-align: center;
    padding: 2rem;
    background: var(--primary-gradient);
    color: white;
    background: #2196f3;
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 1s ease;
}

.result-title {
    font-size: 2rem;
    font-weight: 700;
    color: white;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    padding: 2rem;
    background: var(--bg-primary);
}

.stat-item {
    text-align: center;
    padding: 1.5rem;
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    transition: var(--transition-normal);
}

.stat-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    font-weight: 500;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.time-highlight {
    color: #2196f3;
}

.level-badge {
    padding: 0.5rem 1.5rem;
    border-radius: 20px;
    display: inline-block;
    font-size: 1.125rem;
    font-weight: 600;
}

.level-badge:not(.excellent):not(.normal):not(.weak) {
    background: transparent;
    color: var(--text-primary);
}

.level-badge.excellent {
    background: linear-gradient(135deg, #4caf50, #45a049);
    color: white;
}

.level-badge.normal {
    background: linear-gradient(135deg, #2196f3, #1976d2);
    color: white;
}

.level-badge.weak {
    background: linear-gradient(135deg, #ff9800, #f57c00);
    color: white;
}

/* ==================== 评价内容 ==================== */
.result-feedback {
    padding: 2rem;
    border-top: 1px solid var(--border-color);
}

.feedback-title {
    font-size: 1.125rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.feedback-content p {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 0.5rem;
}

/* ==================== 操作按钮区域 ==================== */
.result-actions {
    padding: 2rem;
    display: flex;
    gap: 1rem;
    justify-content: center;
    border-top: 1px solid var(--border-color);
}

.result-actions .btn {
    flex: 1;
    min-width: 140px;
}

/* ==================== 记录卡片 ==================== */
.records-filter {
    padding: 1rem 2rem 0;
}

.records-filter .form-input {
    width: 100%;
}

.records-content {
    padding: 2rem;
    max-height: 500px;
    overflow-y: auto;
}

.records-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.record-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    background: var(--bg-white);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.record-item:hover {
    border-color: #2196f3;
    box-shadow: var(--box-shadow-hover);
}

.record-rank {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2196f3;
    color: white;
    border-radius: 50%;
    font-weight: bold;
    font-size: 1.125rem;
}

.record-rank.rank-1 {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

.record-rank.rank-2 {
    background: linear-gradient(135deg, #c0c0c0 0%, #e0e0e0 100%);
    box-shadow: 0 4px 12px rgba(192, 192, 192, 0.4);
}

.record-rank.rank-3 {
    background: linear-gradient(135deg, #cd7f32 0%, #ff9800 100%);
    box-shadow: 0 4px 12px rgba(205, 127, 50, 0.4);
}

.record-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.record-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
}

.record-size {
    font-weight: 600;
    color: var(--text-primary);
}

.record-error {
    font-size: 0.875rem;
    color: var(--error-color);
}

.record-date {
    font-size: 0.875rem;
    color: var(--text-light);
}

.record-accuracy {
    font-size: 1.125rem;
    font-weight: 700;
    color: #2196f3;
}

.record-time {
    font-size: 1.125rem;
    font-weight: 700;
    color: #2196f3;
}

/* ==================== 隐藏类 ==================== */
.hidden {
    display: none !important;
}

/* ==================== 动画 ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-20px);
    }
    60% {
        transform: translateY(-10px);
    }
}

/* ==================== 模态框样式 ==================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    opacity: 1;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--box-shadow-lg);
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
    opacity: 1;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    background: var(--primary-gradient);
    color: white;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
}

.btn-close {
    background: transparent;
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.btn-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: 2rem;
    max-height: 60vh;
    overflow-y: auto;
}

/* ==================== 排行榜样式 ==================== */
.leaderboard-content {
    min-height: 200px;
}

.leaderboard-table {
    width: 100%;
    border-collapse: collapse;
}

.leaderboard-table thead {
    background: var(--bg-primary);
}

.leaderboard-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

.leaderboard-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.leaderboard-table tr:hover {
    background: var(--bg-primary);
}

.leaderboard-table .rank {
    font-weight: 700;
    color: #2196f3;
}

.leaderboard-table .user-name {
    font-weight: 600;
    color: var(--text-primary);
}

.leaderboard-table .time,
.leaderboard-table .accuracy {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: #4caf50;
}

.medal {
    display: inline-block;
    margin-left: 0.5rem;
    font-size: 1.2rem;
}

.medal-1::after {
    content: '🥇';
}

.medal-2::after {
    content: '🥈';
}

.medal-3::after {
    content: '🥉';
}

.loading,
.empty,
.error {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.empty-leaderboard {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.leaderboard-item {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    gap: 1rem;
    align-items: center;
    padding: 1rem;
    background: var(--bg-white);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.leaderboard-item:hover {
    border-color: #2196f3;
    box-shadow: var(--box-shadow-hover);
}

.leaderboard-rank {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #2196f3;
    color: white;
    border-radius: 50%;
    font-weight: bold;
    font-size: 1.125rem;
}

.leaderboard-rank.rank-1 {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
}

.leaderboard-rank.rank-2 {
    background: linear-gradient(135deg, #c0c0c0 0%, #e0e0e0 100%);
    box-shadow: 0 4px 12px rgba(192, 192, 192, 0.4);
}

.leaderboard-rank.rank-3 {
    background: linear-gradient(135deg, #cd7f32 0%, #ff9800 100%);
    box-shadow: 0 4px 12px rgba(205, 127, 50, 0.4);
}

.leaderboard-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.leaderboard-name {
    font-weight: 600;
    color: var(--text-primary);
}

.leaderboard-detail {
    font-size: 0.875rem;
    color: var(--text-light);
}

.leaderboard-score {
    font-size: 1.125rem;
    font-weight: 700;
    color: #4caf50;
}

.leaderboard-time {
    font-size: 0.875rem;
    color: var(--error-color);
}

/* ==================== 响应式设计 ==================== */
@media (max-width: 768px) {
    .main-container {
        margin: 1rem auto;
        padding: 0 1rem;
    }
    
    .card-title {
        font-size: 1.25rem;
    }
    
    .game-controls {
        gap: 1rem;
        padding: 1rem;
    }
    
    #restartBtn,
    #backBtn {
        flex: 1;
        min-width: calc(50% - 0.5rem);
        max-width: calc(50% - 0.5rem);
    }
    
    .control-value {
        font-size: 1.25rem;
    }
    
    .number-display {
        font-size: 2.5rem;
        letter-spacing: 8px;
    }
    
    .options-container {
        grid-template-columns: 1fr;
    }
    
    .option-btn {
        font-size: 1.5rem;
        padding: 1.5rem;
    }
    
    .result-stats {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        padding: 0.75rem;
    }

    .stat-item {
        padding: 0.6rem 0.4rem;
    }
    
    .record-item {
        grid-template-columns: auto 1fr;
        gap: 0.75rem;
    }
    
    .result-actions {
        flex-wrap: wrap;
        padding: 1rem;
        gap: 0.5rem;
    }

    .result-actions .btn {
        min-width: 120px;
        flex: 1 1 45%;
        padding: 0.7rem 1rem;
        font-size: 0.9rem;
    }
    
    .local-tip {
        flex-direction: column;
        text-align: center;
    }
    
    .records-filter {
        padding: 0.75rem 1rem 0;
    }

    .modal-content {
        width: 95%;
        max-height: 85vh;
    }

    .modal-header,
    .modal-body {
        padding: 1rem 1.5rem;
    }

    .leaderboard-table {
        font-size: 0.875rem;
    }

    .leaderboard-table th,
    .leaderboard-table td {
        padding: 0.75rem 0.5rem;
    }
}
