/* ============================================
   数学乐园 — 主样式表
   色彩缤纷，适合小朋友的卡通风格
   ============================================ */

/* ─── CSS Variables / Theme ─────────────── */
:root {
    --primary: #6C63FF;
    --primary-light: #8B85FF;
    --secondary: #FF6B6B;
    --accent: #FFD93D;
    --green: #4ECDC4;
    --bg: #f0f4ff;
    --card-bg: #ffffff;
    --text: #2d3436;
    --text-light: #636e72;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 20px rgba(108, 99, 255, 0.12);
    --shadow-hover: 0 8px 30px rgba(108, 99, 255, 0.20);
}

/* ─── Reset & Base ──────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
    width: 100%;
}

/* ─── Navigation ────────────────────────── */
.navbar {
    background: linear-gradient(135deg, var(--primary) 0%, #8B5CF6 100%);
    color: white;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 15px rgba(108, 99, 255, 0.3);
}

.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    max-width: 1100px;
    margin: 0 auto;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: 800;
    color: white;
    text-decoration: none;
    white-space: nowrap;
    letter-spacing: 1px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-links a {
    color: rgba(255,255,255,0.9);
    text-decoration: none;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    font-size: 0.95rem;
    font-weight: 500;
}

.nav-links a:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

.nav-user {
    padding: 8px 12px;
    background: rgba(255,255,255,0.15);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
}

.btn-logout {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.25);
}

.btn-logout:hover {
    background: rgba(255, 107, 107, 0.5) !important;
}

.btn-register {
    background: var(--accent);
    color: #333 !important;
    font-weight: 700 !important;
}

.btn-register:hover {
    background: #ffd700 !important;
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

/* ─── Flash Messages ────────────────────── */
.flash-container {
    max-width: 1100px;
    margin: 10px auto 0;
    padding: 0 20px;
}

.flash-message {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    font-weight: 500;
    display: flex;
    justify-content: space-between;
    align-items: center;
    animation: slideDown 0.4s ease-out;
    transition: opacity 0.5s;
}

.flash-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.flash-error   { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.flash-info    { background: #d1ecf1; color: #0c5460; border: 1px solid #bee5eb; }

.flash-close {
    cursor: pointer;
    font-size: 1.2rem;
    padding: 0 5px;
    opacity: 0.6;
}
.flash-close:hover { opacity: 1; }

/* ─── Buttons ───────────────────────────── */
.btn {
    display: inline-block;
    padding: 10px 24px;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.25s;
    text-align: center;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.15);
}

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

.btn-play {
    background: linear-gradient(135deg, var(--primary), #8B5CF6);
    color: white;
    padding: 12px 30px;
    border-radius: 50px;
    font-size: 1.05rem;
}

.btn-play:hover {
    background: linear-gradient(135deg, #5a52e0, #7c4de6);
    box-shadow: 0 6px 20px rgba(108, 99, 255, 0.4);
}

.btn-big {
    background: linear-gradient(135deg, var(--primary), #8B5CF6);
    color: white;
    padding: 16px 40px;
    border-radius: 50px;
    font-size: 1.2rem;
    box-shadow: 0 6px 20px rgba(108, 99, 255, 0.3);
}

.btn-big:hover {
    box-shadow: 0 8px 30px rgba(108, 99, 255, 0.45);
}

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

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

.btn-answer {
    background: var(--green);
    color: white;
    padding: 12px 30px;
    border-radius: 50px;
    font-size: 1.1rem;
}

.btn-answer:hover {
    background: #3dbdb6;
    box-shadow: 0 4px 15px rgba(78, 205, 196, 0.4);
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
    background: var(--card-bg);
    border: 1px solid #ddd;
    color: var(--text);
    border-radius: var(--radius-sm);
}

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

.btn-form {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary), #8B5CF6);
    color: white;
    border-radius: 50px;
    font-size: 1.1rem;
    font-weight: 700;
    border: none;
    cursor: pointer;
    margin-top: 10px;
    transition: all 0.25s;
}

.btn-form:hover {
    box-shadow: 0 6px 20px rgba(108, 99, 255, 0.4);
    transform: translateY(-2px);
}

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

/* ─── Hero Section (首页) ────────────────── */
.hero {
    text-align: center;
    padding: 60px 20px 40px;
}

.hero-title {
    font-size: 3.5rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

.hero-subtitle {
    font-size: 1.3rem;
    color: var(--text-light);
    margin-bottom: 20px;
}

.hero-welcome {
    font-size: 1.2rem;
    margin-bottom: 25px;
    color: var(--text);
}

.hero-actions {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ─── Game Cards Grid ───────────────────── */
.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    padding: 20px 0 40px;
}

.game-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
    border-top: 5px solid var(--card-color);
    transition: all 0.3s;
    text-decoration: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.game-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-hover);
}

.game-card-icon {
    font-size: 2.8rem;
    display: block;
}

.game-card h2 {
    font-size: 1.4rem;
    color: var(--card-color-text, var(--text));
}

.game-card p {
    color: var(--text-light);
    line-height: 1.6;
}

.game-features {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
}

.game-features li {
    font-size: 0.9rem;
    color: var(--text-light);
}

.game-card .btn-play {
    margin-top: auto;
    align-self: flex-start;
}

/* 迷你卡片（个人中心用） */
.game-card.mini {
    padding: 20px;
    flex-direction: row;
    align-items: center;
    gap: 15px;
}

.game-card.mini .game-card-icon {
    font-size: 2rem;
}

.game-card.mini .best-score {
    font-size: 0.85rem;
    color: var(--text-light);
    margin-left: auto;
}

/* ─── Forms ─────────────────────────────── */
.form-page {
    display: flex;
    justify-content: center;
    padding: 60px 20px;
}

.form-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 420px;
}

.form-title {
    font-size: 2rem;
    text-align: center;
    margin-bottom: 8px;
    color: var(--primary);
}

.form-desc {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 30px;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
    font-size: 0.95rem;
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: border-color 0.2s;
    outline: none;
    background: #fafafa;
}

.form-input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
}

.form-error {
    display: block;
    color: var(--secondary);
    font-size: 0.85rem;
    margin-top: 4px;
}

.form-footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-light);
}

.form-footer a {
    color: var(--primary);
    font-weight: 600;
    text-decoration: none;
}

.form-footer a:hover {
    text-decoration: underline;
}

/* ─── Dashboard ─────────────────────────── */
.dashboard {
    padding: 30px 0;
}

.dash-welcome {
    text-align: center;
    padding: 30px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: var(--radius);
    color: white;
    margin-bottom: 30px;
}

.dash-welcome h1 {
    font-size: 2rem;
    margin-bottom: 5px;
}

.dash-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 16px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 20px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-number {
    display: block;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
}

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

.section-title {
    font-size: 1.5rem;
    margin: 30px 0 16px;
}

.dash-games {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* ─── Recent Table ──────────────────────── */
.recent-table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.recent-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
}

.recent-table th {
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
}

.recent-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
}

.recent-table tr:hover td {
    background: #f8f7ff;
}

.time-cell {
    color: var(--text-light);
    font-size: 0.85rem;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-light);
}

.empty-state p {
    font-size: 1.2rem;
    margin-bottom: 20px;
}

/* ─── Leaderboard Preview (首页) ────────── */
.leaderboard-preview {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
    margin: 20px 0 40px;
}

.leaderboard-preview h2 {
    text-align: center;
    margin-bottom: 16px;
    font-size: 1.5rem;
}

.leaderboard-tabs {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 20px;
}

.lb-tab {
    padding: 8px 20px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.lb-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.lb-content {
    display: none;
}

.lb-content.active {
    display: block;
}

.lb-list {
    list-style: none;
    padding: 0;
}

.lb-list li {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 1.05rem;
}

.lb-list li:last-child { border-bottom: none; }

.lb-loading, .lb-empty {
    text-align: center;
    color: var(--text-light);
    font-style: italic;
}

/* ─── Game Pages (通用) ─────────────────── */
.game-page {
    padding: 20px 0 40px;
}

.game-header {
    text-align: center;
    margin-bottom: 20px;
}

.game-header h1 {
    font-size: 2rem;
    margin-bottom: 16px;
}

.game-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.level-selector, .mode-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.level-selector label, .mode-selector label {
    font-weight: 600;
}

.lv-btn, .mode-btn {
    padding: 8px 18px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 50px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.lv-btn.active, .mode-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.num-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.num-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.num-btn {
    width: 40px;
    height: 40px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 50%;
    cursor: pointer;
    font-weight: 700;
    font-size: 1rem;
    transition: all 0.2s;
}

.num-btn.active {
    background: var(--green);
    color: white;
    border-color: var(--green);
}

/* ─── Game Stats Bar ────────────────────── */
.game-stats-bar {
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    padding: 16px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.stat-item {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
}

.stat-item span {
    color: var(--primary);
    font-size: 1.2rem;
}

/* ─── Question Box ──────────────────────── */
.game-area {
    max-width: 600px;
    margin: 0 auto;
}

.question-box {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 50px 30px;
    text-align: center;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary);
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.answer-area {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.answer-input {
    flex: 1;
    padding: 14px 20px;
    border: 3px solid #e0e0e0;
    border-radius: 50px;
    font-size: 1.3rem;
    text-align: center;
    outline: none;
    transition: border-color 0.2s;
    font-weight: 600;
}

.answer-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.1);
}

/* 去掉number输入框的箭头 */
.answer-input::-webkit-inner-spin-button,
.answer-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.answer-input[type=number] {
    -moz-appearance: textfield;
}

.feedback {
    text-align: center;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 1.1rem;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feedback-success { background: #d4edda; color: #155724; }
.feedback-error   { background: #f8d7da; color: #721c24; }
.feedback-info    { background: #fff3cd; color: #856404; }
.feedback-hint    { background: #cce5ff; color: #004085; }

/* ─── Game Result ───────────────────────── */
.game-result {
    max-width: 500px;
    margin: 40px auto;
}

.result-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px;
    text-align: center;
    box-shadow: var(--shadow);
    animation: fadeIn 0.5s;
}

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

.result-stats p {
    font-size: 1.15rem;
    margin: 10px 0;
    color: var(--text);
}

.result-stats span {
    font-weight: 800;
    color: var(--secondary);
    font-size: 1.3rem;
}

.result-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 30px;
    flex-wrap: wrap;
}

/* ─── Multiplication Table ──────────────── */
.multiplication-table-wrapper {
    overflow-x: auto;
    margin-bottom: 20px;
}

.multiplication-table {
    margin: 0 auto;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.multiplication-table td {
    padding: 10px 16px;
    border: 1px solid #f0f0f0;
    text-align: center;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s;
    cursor: default;
}

.multiplication-table td.mastered {
    background: #d4edda;
    color: #155724;
    font-weight: 700;
}

.multiplication-table td.learning {
    background: #fff3cd;
    color: #856404;
    font-weight: 700;
}

/* ─── Progress Bar ──────────────────────── */
.progress-bar-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
    background: #f0f0f0;
    border-radius: 50px;
    padding: 4px;
}

.progress-bar {
    height: 12px;
    background: linear-gradient(90deg, var(--green), var(--primary));
    border-radius: 50px;
    transition: width 0.5s ease;
    width: 0%;
}

.progress-bar-wrapper span {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-light);
    white-space: nowrap;
    padding-right: 8px;
}

/* ─── Cards (24点) ──────────────────────── */
.cards-row {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 30px 0;
    flex-wrap: wrap;
}

.card {
    width: 100px;
    height: 140px;
    background: linear-gradient(145deg, #ffffff, #f0f0f0);
    border: 3px solid #ddd;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--text);
    box-shadow: 4px 4px 10px rgba(0,0,0,0.1);
    transition: all 0.3s;
    opacity: 0;
    transform: translateY(20px);
}

.card.card-dealt {
    opacity: 1;
    transform: translateY(0);
}

.card:hover {
    transform: translateY(-5px);
    box-shadow: 6px 6px 15px rgba(0,0,0,0.15);
}

.operation-area {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.operation-area .prompt {
    text-align: center;
    margin-bottom: 16px;
    font-size: 1.1rem;
    color: var(--text);
}

.hint-area {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 12px;
}

/* ─── Footer ────────────────────────────── */
.footer {
    background: var(--text);
    color: rgba(255,255,255,0.7);
    text-align: center;
    padding: 20px;
    margin-top: auto;
}

.footer p {
    font-size: 0.9rem;
}

/* ─── Animations ────────────────────────── */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-60px) scale(1.5); }
}

/* ─── Responsive ────────────────────────── */
@media (max-width: 768px) {
    .hero-title {
        font-size: 2.5rem;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 60px;
        left: 0;
        right: 0;
        background: var(--primary);
        padding: 16px;
        box-shadow: 0 8px 20px rgba(0,0,0,0.2);
    }

    .nav-links.show {
        display: flex;
    }

    .nav-toggle {
        display: block;
    }

    .games-grid {
        grid-template-columns: 1fr;
    }

    .question-box {
        font-size: 1.8rem;
        padding: 30px 20px;
        min-height: 100px;
    }

    .card {
        width: 70px;
        height: 100px;
        font-size: 1.8rem;
    }

    .game-stats-bar {
        gap: 12px;
        padding: 12px 16px;
        font-size: 0.9rem;
    }

    .answer-input {
        font-size: 1.1rem;
        padding: 12px 16px;
    }

    .form-card {
        padding: 24px;
    }

    .result-card {
        padding: 24px;
    }

    .multiplication-table td {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .hero-title {
        font-size: 2rem;
    }

    .hero-subtitle {
        font-size: 1rem;
    }

    .game-header h1 {
        font-size: 1.5rem;
    }

    .question-box {
        font-size: 1.4rem;
        padding: 20px 16px;
        min-height: 80px;
    }
}
