:root {
    /* 男孩系马卡龙配色 - 浅色模式 */
    --bg-color: #F0F0F0;
    --bg-color2: #E0E0E0;
    --card-bg: #ffffff;
    --text-color: #2D3436;
    --text-color2: #696969;
    --primary-color: #4facfe; /* 天蓝色 */
    --secondary-color: #00f2fe; /* 浅青 */
    --accent-color: #aaccee; /* 薄荷绿 */
    --button-color: #a1c4fd; /* 淡蓝 */
    --error-color: #ec6671; /* 浅红 */
    --success-color: #8addaa; /* 草绿 */
    --pg-arrow-color: #5CB6FF; /* 进度箭头颜色 */ 
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s ease;
}

[data-theme="dark"] {
    /* 夜间模式 */
    --bg-color: #2c3e50;
    --bg-color2: #34495e;
    --card-bg: #34495e;
    --text-color: #ecf0f1;
    --text-color2: #dddddd;
    --primary-color: #3498db; 
    --secondary-color: #2980b9;
    --accent-color: #667a8d;
    --button-color: #2980b9;
    --error-color: #b64134;
    --success-color: #2ecc71;
    --pg-arrow-color: #28335b; /* 夜间模式进度箭头颜色 */ 
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    overflow-x: hidden;
}

/* 大标题样式 - 移到外部居中 */
.main-title {
    text-align: center;
    color: var(--primary-color);
    font-size: 1.8rem;
    margin: 30px 0 10px 0;
}

/* 通用容器 - 宽度改为600px与数学小达人一致 */
.container {
    width: 95%;
    max-width: 600px;
    margin: 15px auto;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 24px;
    box-shadow: var(--shadow);
    text-align: center;
}

h1 { margin-top: 0; color: var(--primary-color); font-size: 1.8rem; }
p { font-size: 1rem; line-height: 1.5; }

/* 设置界面样式 - 增加上部留空至2倍 */
.setting-group {
    text-align: left;
    margin-bottom: 15px;
    margin-top: 30px;
}
h2 { 
    border-bottom: 2px solid var(--bg-color); 
    padding-bottom: 10px; 
    font-size: 1.2rem; 
    margin-top: 0;
}

/* 网格选项样式 (参考数学小达人) */
.grid-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-bottom: 5px;
}

.grid-item {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    background: var(--bg-color);
    padding: 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    user-select: none;
}

.grid-item:active {
    transform: scale(0.95);
}

/* 选中状态 - 更淡更粉的蓝色，无绿色边框 */
.grid-item.selected {
    background: #a1c4fd;
    color: #2D3436;
}

[data-theme="dark"] .grid-item.selected {
    background: #5e8ec9;
    color: white;
}

.grid-item input {
    display: none;
}

select, input[type="number"] {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 2px solid var(--button-color);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
}

/* 按钮样式 */
.btn {
    display: inline-block;
    padding: 12px 24px;
    margin: 8px 4px;
    border-radius: 15px;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    font-weight: bold;
    transition: var(--transition);
    touch-action: manipulation;
}
.btn:active { transform: scale(0.95); }
.btn-primary { background-color: var(--primary-color); color: white; font-size: 1.2rem; }
.btn-secondary { background-color: var(--button-color); color: var(--text-color); }
.btn-accent { background-color: var(--accent-color); color: var(--text-color); }
.btn-danger { background-color: var(--error-color); color: white; }

/* 弹窗/模态框 */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    display: none; /* 通过 JS 控制 */
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.modal {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 28px;
    width: 95%;
    max-width: 500px;
    box-shadow: var(--shadow);
    position: relative;
}

/* 答题界面 */
.quiz-question { font-size: 3rem; margin-top: 20px; font-weight: bold; white-space: nowrap; overflow: hidden; }
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-top: 20px;
}
.keypad button {
    padding: 20px;
    font-size: 1.5rem;
    border-radius: 15px;
    border: none;
    background: var(--button-color);
    color: var(--text-color);
    cursor: pointer;
}
.keypad button:active { background: var(--primary-color); color: white; }
/* 答题按钮颜色加深 */
#submitBtn { background: var(--primary-color) !important; color: white !important; font-weight: bold; }
#submitBtn:active { background: #3a8fd8 !important; }
[data-theme="dark"] #submitBtn { background: #223750 !important; color: white !important; }
/* C键改为清除，灰色系 */
.key-clear { background: #e8e8e8 !important; color: #555 !important; font-size: 1rem !important; }
[data-theme="dark"] .key-clear { background: #4a4a4a !important; color: #ccc !important; }
/* 清除按钮点击时的样式反馈 */
.key-clear:active { background: #bbb !important; color: #333 !important; }
[data-theme="dark"] .key-clear:active { background: #666 !important; color: #eee !important; }

/* 删除记录项样式 */
.delete-record-item {
    transition: var(--transition);
    opacity: 0.4;
}
.delete-record-item.selected {
    background-color: #F0F0F0;
    opacity: 0.8;
}
[data-theme="dark"] .delete-record-item.selected {
    background-color: #4a4a4a;
    color: #ddd;
}

/* 取消按钮 - 灰色 */
.btn-cancel {
    background-color: #e0e0e0 !important;
    color: #333 !important;
}
[data-theme="dark"] .btn-cancel {
    background-color: #666 !important;
    color: #ddd !important;
}

/* 确定按钮 - 蓝色 */
.btn-confirm {
    background-color: #a1c4fd !important;
    color: #2D3436 !important;
    font-weight: bold;
}
[data-theme="dark"] .btn-confirm {
    background-color: #5e8ec9 !important;
    color: white !important;
}

/* 历史记录列表 - 分割线改为灰色系 */
.history-list {
    max-height: 300px;
    overflow-y: auto;
    text-align: left;
    margin-top: 15px;
}

/* 时间线分组样式 */
.timeline-group {
    margin-bottom: 20px;
    position: relative;
}

.timeline-date-header {
    font-size: 1rem;
    color: var(--primary-color);
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
    margin: 15px 0 10px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.timeline-group-summary {
    font-size: 0.75rem;
    color: gray;
    background: var(--bg-color);
    padding: 2px 8px;
    border-radius: 10px;
}

.history-item {
    padding: 12px;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
    margin-left: 15px;
    position: relative;
    transition: var(--transition);
    display: grid;
    grid-template-columns: 1.2fr 0.8fr 0.8fr; /* 时间 | 得分 | 正确率 */
    align-items: center;
}

.history-item .item-time { text-align: left; }
.history-item .item-score { text-align: center; }
.history-item .item-rate { text-align: right; color: var(--primary-color); }

.history-item:hover {
    background: rgba(0,0,0,0.02);
}

/* 统计详情样式 */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 15px;
}

.stat-card {
    background: var(--bg-color);
    padding: 10px;
    border-radius: 12px;
    text-align: center;
}

.stat-value {
    display: block;
    font-size: 1.2rem;
    color: var(--primary-color);
}

.stat-label {
    font-size: 0.75rem;
    color: gray;
}

.op-distribution {
    list-style: none;
    padding: 0;
    margin: 10px 0;
}

.op-item {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    border-bottom: 1px dashed #ddd;
    font-size: 0.85rem;
}

.mastery-stat-row {
    display: grid;
    grid-template-columns: 45px 45px 0.4fr 0.2fr 0.4fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 15px;
    font-size: 0.9rem;
    border-bottom: 1px dashed #ddd;
    padding-bottom: 8px;
}

[data-theme="dark"] .mastery-stat-row {
    border-bottom-color: #444;
}

/* 夜间模式切换 */
.theme-toggle {
    position: fixed;
    right: 20px;
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1001;
}

#themeToggle {
    top: 20px;
}

/* 管理菜单样式 */
.admin-menu {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 20px 0;
}

.admin-item {
    text-align: left;
    padding: 15px;
    font-size: 1.1rem;
}

/* 隐藏元素 */
.hidden { display: none !important; }

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-fade { animation: fadeIn 0.3s ease forwards; }

/* 礼花 Canvas */
#canvas-confetti {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 9999;
}

/* 底部控制栏按钮样式 (弱化) */
.quiz-footer {
    margin-top: 25px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 10px;
}
.btn-footer {
    flex: 1;
    max-width: 140px;
    font-size: 0.8rem;
    padding: 8px 8px;
    margin: 0px 8px;
    border-radius: 10px;
    background: transparent;
    border: 2px solid var(--button-color);
    color: var(--text-color);
    opacity: 0.7;
    cursor: pointer;
}
.btn-footer:hover { opacity: 1; }
.btn-footer:active { opacity: 1; }

/* 补做按钮 — 淡红色 */
#reviewBtn {
    background-color: #ffe0e0 !important;
    color: #c0392b !important;
    border-color: #ffcccc !important;
    opacity: 1 !important;
}
[data-theme="dark"] #reviewBtn {
    background-color: #4a2020 !important;
    color: #ff8a80 !important;
    border-color: #5a3030 !important;
}

/* 关闭按钮样式 */
.close-quiz-btn {
    position: absolute;
    top: 15px; right: 15px;
    font-size: 1.2rem;
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    opacity: 0.6;
}

/* 自定义输入框样式 */
.custom-input-area input {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 2px solid var(--button-color);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 1rem;
    outline: none;
    text-align: center;
}

/* 日历样式 */
.calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 5px;
    padding: 10px;
    background: var(--bg-color);
    border-radius: 12px;
    margin-bottom: 10px;
}
.calendar-day {
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    border-radius: 50%;
    cursor: pointer;
}

/* 历史记录布局增强 */
.history-nav-container {
    background: var(--bg-color);
    padding: 10px;
    border-radius: 12px;
}

.view-switch-container .btn-secondary {
    flex: 1;
    min-width: 80px;
}

.view-switch-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    background: var(--bg-color2);
    padding: 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
    user-select: none;
}

.view-switch-btn.active-view-btn {
    background: #a1c4fd !important;
    color: #2D3436 !important;
}

[data-theme="dark"] .view-switch-btn.active-view-btn {
    background: #5e8ec9 !important;
    color: white !important;
}

.history-nav-row select {
    padding: 6px 8px;
    font-size: 0.85rem;
    border-radius: 8px;
    border: 1px solid var(--button-color);
    background: var(--card-bg);
    color: var(--text-color);
}

/* 历史记录头部导航区 */
.history-header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 15px;
    flex-shrink: 0;
}

.history-nav-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-color);
    padding: 8px 12px;
    border-radius: 12px;
    gap: 8px;
}

.history-nav-row .nav-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.history-nav-row select#timelineYearSelect {
    width: 100px;
}

.history-nav-row select#timelineMonthSelect {
    width: 80px;
}

.history-nav-row .nav-month-display {
    font-size: 0.9rem;
    min-width: 50px;
    text-align: center;
}

/* 时间轴日期行静态布局 */
.timeline-date-row-static {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    background: var(--bg-color);
    border-radius: 12px;
    margin: 12px 0 8px 0;
    cursor: pointer;
}

/* 静态行不需要 active 状态 */
.timeline-date-row-static .btn-day-detail {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

/* 新格式的历史记录项 */
.history-item-new {
    padding: 8px 12px;
    border-bottom: 1px solid #eee;
    font-size: 0.85rem;
    transition: var(--transition);
    display: grid;
    grid-template-columns: auto auto auto auto 60px; /* 时间 | 题数 | 正确 | 错误 | 百分比 */
    gap: 6px;
    align-items: center;
    cursor: pointer;
}

[data-theme="dark"] .history-item-new {
    border-bottom-color: #444;
}

.history-item-new:hover {
    background: rgba(0,0,0,0.02);
}

.history-item-new .item-time {
    color: var(--text-color2);
    font-size: 0.85rem;
    text-align: left;
    white-space: nowrap;
}

.history-item-new .item-question-count {
    padding: 2px 6px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-color2);
    text-align: right;
    white-space: nowrap;
}

.history-item-new .item-stat {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.85rem;
    justify-content: center;
    white-space: nowrap;
}

.history-item-new .item-rate {
    color: var(--text-color2);
    font-weight: normal;
    text-align: right;
    min-width: 50px;
    white-space: nowrap;
}

/* 统计徽章图标样式 */
.stat-icon-correct {
    color: #2ecc71;
}

.stat-icon-wrong {
    color: #e74c3c;
}

/* 统计标签样式 */
.stat-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    margin: 0 4px;
}

/* 日历状态优化 */
.calendar-day.active {
    background: #a1c4fd !important;
    color: #2D3436 !important;
    box-shadow: 0 0 8px rgba(79, 172, 254, 0.5);
}
.calendar-day.has-data { background: var(--accent-color); color: var(--text-color); }
.calendar-day.today { border: 2px solid var(--primary-color); }

/* 未选中/无数据状态 */
.calendar-day:not(.active):not(.has-data) {
    background: var(--bg-color2);
    color: #bbb;
}
[data-theme="dark"] .calendar-day:not(.active):not(.has-data) {
    background: #3a3f47;
    color: #666;
}

/* 详情按钮样式 */
.btn-day-detail {
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
    cursor: pointer;
}

/* 移除旧的 .timeline-date-row-new.active 相关样式 */
.detail-modal-container {
    display: flex;
    flex-direction: column;
    max-height: 85vh !important;
}
.detail-scroll-area {
    overflow-y: auto;
    flex: 1;
    padding-right: 5px;
}

/* 题目解析固定顶部区域 */
#answerDetailFixed {
    text-align: center;
    margin-bottom: 10px;
}
.detail-footer {
    padding-top: 15px;
    margin-top: 10px;
}

/* 详情页表格样式 */
.detail-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

/* 单题答案大字号及解题思路样式 */
.big-answer {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    text-align: center;
    margin: 10px 0;
}

.solution-step {
    background: var(--bg-color);
    padding: 10px;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 15px;
    text-align: center;
}

.solution-vertical {
    font-family: 'Courier New', Courier, monospace;
    white-space: pre;
    text-align: right;
    padding: 12px 16px;
    margin: 8px auto;
    background: var(--card-bg);
    border-radius: 6px;
    display: inline-block;
    font-size: 1.1rem;
    line-height: 1.5;
    letter-spacing: 2px;
}

.solution-step .carry-mark {
    color: var(--primary-color);
}

.solution-step .borrow-mark {
    color: var(--error-color);
}

.solution-verbal {
    margin-top: 8px;
    text-align: left;
    padding-left: 10px;
}

.solution-verbal li {
    margin-bottom: 4px;
    list-style: none;
    position: relative;
    padding-left: 16px;
}

.solution-verbal li::before {
    content: '▸';
    position: absolute;
    left: 0;
    color: var(--primary-color);
}

/* 混合运算步骤块 */
.mixed-step-block {
    margin: 12px 0;
    padding: 8px 12px;
    background: var(--bg-color);
    border-radius: 6px;
}

/* 竖式横向排列容器 */
.mixed-vertical-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin: 8px 0;
}
.mixed-vertical-row .solution-vertical {
    flex: 0 0 auto;
}

.detail-table td {
    padding: 8px 4px;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
    text-align: center;
}
[data-theme="dark"] .detail-table td { border-bottom: 1px solid #444; }

.detail-table .col-num { width: 15%; }
.detail-table .col-q { width: 40%; text-align: left; }
.detail-table .col-ans { width: 25%; }
.detail-table .col-res { width: 20%; font-weight: bold; }

/* 单次练习统计区域 */
.session-stats {
    background: var(--bg-color);
    padding: 15px;
    border-radius: 15px;
    margin-top: 20px;
}
.session-stats h3 {
    font-size: 0.9rem;
    margin: 0 0 10px 0;
}
.session-stat-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 5px;
}

/* 草稿纸相关样式 */
.scratch-pad-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #f5e9d3;
    z-index: 2000;
    display: none;
}

[data-theme="dark"] .scratch-pad-container {
    background: #1a1a2e;
}

.scratch-pad-header {
    position: fixed;
    top: 15px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.8rem;
    font-weight: bold;
    color: #333;
    z-index: 2002;
    pointer-events: none; /* 不拦截点击事件 */
    white-space: nowrap;
}

[data-theme="dark"] .scratch-pad-header {
    color: #ecf0f1;
}

.scratch-pad-container canvas {
    width: 100%;
    height: 100%;
    touch-action: none;
    display: block;
}

.scratch-controls {
    position: fixed;
    top: 15px; right: 15px;
    display: flex;
    gap: 8px;
    z-index: 2001;
}

.scratch-control-btn {
    background: rgba(0, 0, 0, 0.08);
    border: none;
    font-size: 1.4rem;
    width: 44px; height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.scratch-control-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] .scratch-control-btn {
    background: rgba(255, 255, 255, 0.15);
}

[data-theme="dark"] .scratch-control-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* 确保 canvas 占满整个容器 */
.scratch-pad-container canvas {
    width: 100%;
    height: 100%;
    touch-action: none;
    display: block;
}

.scratch-controls {
    position: fixed;
    top: 15px; right: 15px;
    display: flex;
    gap: 8px;
    z-index: 2001;
}

.scratch-control-btn {
    background: rgba(0, 0, 0, 0.08);
    border: none;
    font-size: 1.4rem;
    width: 44px; height: 44px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.scratch-control-btn:hover {
    background: rgba(0, 0, 0, 0.15);
}

.scratch-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    padding: 8px;
    cursor: pointer;
    margin-right: 15px;
    flex-shrink: 0;
}

/* Progress bar styles */
.progress-container {
    width: 100%;
    margin: 30px 0;
    position: relative;
}
.progress-arrow {
    width: 8px;
    height: 4px;
    position: absolute;
    left: 0;
    top: 0;
    z-index: 1;
}
.progress-arrow::after {
    content: '';
    display: block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid var(--pg-arrow-color);
}
/* 深色模式已通过 --pg-arrow-color 变量控制 */
.progress-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 0;
    width: 100%;
}
.progress-row {
    display: flex;
    width: 100%;
    height: 20px;
}
.progress-item {
    flex: 1;
    margin-right: 2px;
    border-radius: 4px;
}
.progress-item:last-child {
    margin-right: 0;
}
.unanswered {
    background: var(--bg-color2, #E0E0E0);
}
.answered {
    background: var(--success-color, #b2f2bb);
}
.skipped {
    background: var(--error-color, #ff9aa2);
}
.progress-stats {
    text-align: center;
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--text-color2, #696969);
}
.progress-stats .stat-item {
    display: inline;
    margin: 0 16px;
}
.stat-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 4px;
    vertical-align: middle;
}
[data-theme="dark"] .unanswered {
    background: #556677;
}
[data-theme="dark"] .answered {
    background: var(--success-color, #2ecc71);
}
[data-theme="dark"] .skipped {
    background: var(--error-color, #e74c3c);
}
