/* ===== 1. 全局样式变量 ===== */
:root {
    --primary-color: #7b68ee;
    --primary-light: #f0eeff;
    --bg-color: #ffffff;
    --card-bg: rgba(255, 255, 255, 0.78);
    --text-main: #2d2d5f;
    --text-sub: #8a87b8;
    --success: #84cc16;
    --danger: #ef4444;
    --border-color: rgba(123, 104, 238, 0.3);
    --shadow: 0 12px 40px rgba(123, 104, 238, 0.12);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    color: var(--text-main);
    line-height: 1.6;
    padding: 15px;
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

/* ===== 2. 动态数学背景 (核心修复) ===== */
#math-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
    background: linear-gradient(135deg, #ffffff 0%, #f4f5ff 100%);
    /* 修复：设为 none，点击会穿透到上层的 UI 按钮 */
    pointer-events: none; 
    transform: translateZ(0);
}

.math-symbol {
    position: absolute;
    font-family: "Comic Sans MS", "Chalkboard SE", "Quicksand", sans-serif;
    font-weight: 900;
    user-select: none;
    white-space: nowrap;
    will-change: transform, opacity;
    display: block;
    cursor: default;
    transition: transform 0.2s ease-out, opacity 0.3s ease, text-shadow 0.3s ease;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    /* 修复：恢复点击交互 */
    pointer-events: auto;
}

/* ===== 3. 身份验证 (Auth) 样式 ===== */
.auth-box {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
}

.auth-card {
    background: #ffffff;
    padding: 30px;
    border-radius: 28px;
    box-shadow: var(--shadow);
    width: 100%;
    text-align: center;
    border: 2px solid var(--border-color);
    pointer-events: auto;
}

.auth-tabs {
    display: flex;
    background: #f4f4ff;
    padding: 5px;
    border-radius: 16px;
    margin-bottom: 25px;
    border: 1px solid var(--border-color);
}

.auth-tabs button {
    flex: 1;
    padding: 12px;
    border: none;
    background: none;
    border-radius: 12px;
    color: var(--text-sub);
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.auth-tabs button.active {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 4px 15px rgba(123, 104, 238, 0.15);
}

/* ===== 4. 输入与按钮样式 ===== */
.input-group input {
    margin-bottom: 12px;
}

input[type="text"], input[type="number"], input[type="email"], input[type="password"] {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid #eeecff;
    border-radius: 16px;
    outline: none;
    transition: all 0.3s;
    font-size: 16px;
    background-color: #fff;
    -webkit-appearance: none;
    display: block;
}

input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(123, 104, 238, 0.1);
}

.primary-btn {
    background: linear-gradient(135deg, var(--primary-color) 0%, #9584ff 100%);
    color: white;
    border: none;
    padding: 16px;
    border-radius: 16px;
    font-weight: 700;
    width: 100%;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(123, 104, 238, 0.25);
}

.primary-btn:active {
    transform: scale(0.97);
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-sub);
    font-size: 13px;
    text-decoration: underline;
    cursor: pointer;
    margin-top: 15px;
}

/* ===== 5. 应用卡片 (Section) ===== */
section {
    background: var(--card-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 28px;
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 2px solid var(--border-color);
    position: relative;
    z-index: 10;
    /* 修复：恢复点击交互 */
    pointer-events: auto;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 5px 15px;
    font-size: 14px;
    color: var(--text-sub);
}

/* ===== 新增：用户头像与弹窗样式 ===== */
.user-info-trigger {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 16px;
    transition: background 0.2s;
    background: rgba(255, 255, 255, 0.5);
}

.user-info-trigger:hover {
    background: rgba(255, 255, 255, 0.9);
}

.status-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(123, 104, 238, 0.2);
}

.status-name {
    font-weight: 700;
    color: var(--text-main);
}

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.4); z-index: 2000;
    display: flex; justify-content: center; align-items: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 28px;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: fadeInMenu 0.3s ease-out;
    border: 2px solid var(--border-color);
}

/* ===== 弹窗内提示条（用于密码重置引导） ===== */
.inline-notice {
    border-radius: 18px;
    padding: 14px 14px;
    margin: 0 0 14px 0;
    background: linear-gradient(135deg, rgba(123, 104, 238, 0.12) 0%, rgba(255, 156, 110, 0.10) 100%);
    border: 1px solid rgba(123, 104, 238, 0.25);
    color: var(--text-main);
    text-align: center;
}

.inline-notice-title {
    font-weight: 800;
    font-size: 14px;
    margin-bottom: 4px;
}

.inline-notice-desc {
    font-size: 12px;
    color: var(--text-sub);
    line-height: 1.4;
}

/* 专门针对退出登录按钮的精准修正 */
.status-bar button {
    background: #fff0f0;
    color: #ff4d4f;
    border: 1px solid #ffccc7;
    padding: 6px 14px;
    border-radius: 10px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.status-bar button:active {
    transform: scale(0.95);
    background: #ffe5e5;
}

.calendar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 12px;
}

.month-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

#currentMonthLabel {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    min-width: 80px;
    text-align: center;
}

.nav-btn {
    background: #f0f0ff;
    border: 1px solid var(--border-color);
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    cursor: pointer;
}

/* ===== 6. 下拉选择器 ===== */
.subject-select-wrap {
    position: relative;
    width: 130px;
    flex-shrink: 0;
}

.custom-select-trigger {
    background: white;
    border: 2px solid var(--border-color);
    height: 38px;
    padding: 0 12px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.custom-options {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.12);
    z-index: 100;
    display: none;
    overflow: hidden;
    border: 2px solid var(--border-color);
}

.custom-options.show {
    display: block;
    animation: fadeInMenu 0.25s ease-out;
}

@keyframes fadeInMenu {
    from { opacity: 0; transform: translateY(-10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.custom-option {
    padding: 12px;
    text-align: center;
    font-size: 13px;
    color: var(--text-main);
    cursor: pointer;
}

.custom-option:hover, .custom-option.active {
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 700;
}

/* ===== 7. 日历网格布局 ===== */
.calendar-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 12px;
    color: var(--text-sub);
    margin-bottom: 10px;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
}

.day-cell {
    aspect-ratio: 1;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background-color: #f1f3f9;
    border: 2px solid transparent;
}

.day-cell.level-1 { background-color: #ef4444 !important; color: white; }
.day-cell.level-2 { background-color: #facc15 !important; color: #7c2d12; }
.day-cell.level-3 { background-color: #84cc16 !important; color: white; }
.day-cell.level-4 { background-color: #166534 !important; color: white; }
.day-cell.level-0 { background-color: #f1f3f9; color: var(--text-main); }

.day-cell.selected {
    border-color: var(--primary-color);
    box-shadow: 0 0 15px rgba(123, 104, 238, 0.3);
    transform: scale(0.88);
    background-color: white !important;
    color: var(--primary-color) !important;
    z-index: 2;
}

.legend {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: var(--text-sub);
    margin-top: 18px;
    gap: 6px;
}

.legend-box {
    width: 12px;
    height: 12px;
    border-radius: 4px;
}

.legend-box.lv1 { background: #ef4444; }
.legend-box.lv2 { background: #facc15; }
.legend-box.lv3 { background: #84cc16; }
.legend-box.lv4 { background: #166534; }

/* ===== 8. 错题记录与分页 ===== */
#wrongCalendar {
    display: flex !important;
    overflow-x: auto !important;
    gap: 10px;
    padding: 10px 5px;
    scrollbar-width: none;
}

#wrongCalendar::-webkit-scrollbar { display: none; }

.history-date-badge {
    flex: 0 0 auto;
    padding: 10px 20px;
    background: white;
    border-radius: 14px;
    border: 2px solid var(--border-color);
    color: var(--primary-color);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.wrong-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 16px;
    margin-bottom: 10px;
}

.delete-btn {
    background: #fff0f0;
    color: #ff4d4f;
    border: 1px solid #ffccc7;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 12px;
    cursor: pointer;
}

/* ===== 9. 勋章弹窗与动画 ===== */
#medalPopup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.5);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    width: 140px;
    height: 140px;
    border-radius: 35px;
    border: 2px solid rgba(123, 104, 238, 0.4);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    animation: medalPopScale 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

#medalPopup span {
    font-size: 64px;
    filter: drop-shadow(0 10px 15px rgba(123, 104, 238, 0.3));
    user-select: none;
}

@keyframes medalPopScale {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
    100% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* ===== 10. 勋章墙布局 ===== */
.medal-stats-bar {
    display: flex;
    justify-content: space-around;
    background: rgba(248, 248, 255, 0.6);
    padding: 18px;
    border-radius: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
}

.honor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.honor-item {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 18px;
    text-align: center;
    transition: transform 0.3s;
}

.honor-item:hover { transform: translateY(-5px); }

.pagination-controls {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    width: 100% !important;
    gap: 15px;
    margin-top: 25px;
}

.page-btn {
    background: #f0f0ff;
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 12px;
    color: var(--primary-color);
    font-weight: 700;
    cursor: pointer;
    min-width: 80px;
}

.page-btn:disabled {
    color: #ccc;
    background: #f5f5f5;
    border-color: #eee;
    cursor: not-allowed;
}

/* ===== 11. 媒体查询 (适配手机端) ===== */
@media (max-width: 380px) {
    section { padding: 18px; }
    #currentMonthLabel { font-size: 14px; min-width: 70px; }
    .calendar-grid { gap: 6px; }
    .day-cell { border-radius: 10px; font-size: 13px; }
    #medalPopup { width: 110px; height: 110px; }
    #medalPopup span { font-size: 48px; }
}