/* =========================================
   1. 本地字体注册 (Local Fonts)
   文件路径对应: fonts/文件名.ttf
========================================= */

/* 400 - 标准体 (Regular) */
@font-face {
    font-family: 'Nunito';
    src: url('fonts/Nunito-Regular.ttf') format('truetype'); 
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* 600 - 半粗体 (SemiBold) - 对应 Screenshot 里缺少的，请放入 */
@font-face {
    font-family: 'Nunito';
    src: url('fonts/Nunito-SemiBold.ttf') format('truetype');
    font-weight: 600;
    font-style: normal;
    font-display: swap;
}

/* 700 - 粗体 (Bold) - 对应 Screenshot 里的 Nunito-Bold.ttf */
@font-face {
    font-family: 'Nunito';
    src: url('fonts/Nunito-Bold.ttf') format('truetype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}

/* 800 - 特粗体 (ExtraBold) - 对应 Screenshot 里缺少的，请放入 */
@font-face {
    font-family: 'Nunito';
    src: url('fonts/Nunito-ExtraBold.ttf') format('truetype');
    font-weight: 800;
    font-style: normal;
    font-display: swap;
}

/* =========================================
   2. 全局变量定义
========================================= */
:root {
    /* ... 颜色变量保持不变 ... */
    --bg-color: #F7F5ED; 
    --text-main: #2c3e50;
    --text-sub: #7f8c8d;
    --accent: #FF7E67;
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.4);
    --shadow-soft: 0 8px 32px 0 rgba(31, 38, 135, 0.08);
    
    /* 【修改这里】强制优先使用本地注册的 Nunito */
    --font-stack: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    
    --book-width: 100px;
    --book-height: 140px; 
}

/* ... 下面所有的 CSS 代码保持原样 ... */
:root {
    --bg-color: #F7F5ED; 
    --text-main: #2c3e50;
    --text-sub: #7f8c8d;
    --accent: #FF7E67;
    --glass-bg: rgba(255, 255, 255, 0.65);
    --glass-border: rgba(255, 255, 255, 0.4);
    --shadow-soft: 0 8px 32px 0 rgba(31, 38, 135, 0.08);
    --font-stack: 'Nunito', -apple-system, sans-serif;
    --book-width: 100px;
    --book-height: 140px; 
}

body.has-custom-bg {
    --glass-bg: rgba(255, 255, 255, 0.25); 
    --glass-border: rgba(255, 255, 255, 0.2);
    --text-main: #1a252f;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a; 
    --text-main: #ecf0f1;
    --text-sub: #bdc3c7;
    --glass-bg: rgba(30, 30, 30, 0.65);
    --glass-border: rgba(255, 255, 255, 0.1);
    --shadow-soft: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] body.has-custom-bg {
    --glass-bg: rgba(0, 0, 0, 0.4);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #ffffff;
}

body.has-custom-bg .modern-todo-item {
    border-left: 4px solid rgba(255,255,255,0.8);
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(25px);
}
[data-theme="dark"] body.has-custom-bg .modern-todo-item {
    border-left: 4px solid rgba(255,255,255,0.3);
    background: rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; outline: none; }
body { margin: 0; font-family: var(--font-stack); background: var(--bg-color); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; background-size: cover; background-position: center; transition: background 0.3s; }

.glass-panel { background: var(--glass-bg); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--glass-border); box-shadow: var(--shadow-soft); transition: background 0.5s ease; }

header { padding: 16px 24px; display: flex; justify-content: space-between; align-items: center; z-index: 10; }
h1 { margin: 0; font-size: 20px; font-weight: 800; }
main { flex: 1; overflow-y: auto; padding: 20px; position: relative; z-index: 1; overflow-x: hidden; }

#theme-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.page { display: none; }
.page.active { display: block; }
.page.active.turn-next { animation: slide-in-right 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
.page.active.turn-prev { animation: slide-in-left 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) forwards; }
@keyframes slide-in-right { 0% { opacity: 0; transform: translateX(50px); } 100% { opacity: 1; transform: translateX(0); } }
@keyframes slide-in-left { 0% { opacity: 0; transform: translateX(-50px); } 100% { opacity: 1; transform: translateX(0); } }

nav { padding-bottom: env(safe-area-inset-bottom); display: flex; justify-content: space-around; border-radius: 20px 20px 0 0; border-bottom: none; }
.nav-item { padding: 14px; flex: 1; text-align: center; color: var(--text-sub); font-size: 12px; cursor: pointer; transition: all 0.2s; font-weight: 700; }
.nav-item.active { color: var(--accent); transform: translateY(-2px); }
.nav-icon { font-size: 22px; display: block; margin-bottom: 4px; }

.card { border-radius: 24px; padding: 24px; text-align: center; margin-bottom: 24px; }
.btn { background: var(--accent); color: white; border: none; padding: 12px 24px; border-radius: 50px; font-size: 15px; font-weight: 700; cursor: pointer; transition: transform 0.1s; }
.btn:active { transform: scale(0.95); }
.btn.secondary { background: rgba(255,255,255,0.5); color: var(--text-main); border: 1px solid var(--glass-border); }
.btn.danger { background: #ff4757; }

.btn.running {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid var(--accent); 
    color: var(--text-main);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    animation: pulse-soft 2s infinite;
}
[data-theme="dark"] .btn.running {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
@keyframes pulse-soft {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4); }
    70% { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(255, 255, 255, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}

.timer-display { font-size: 72px; font-weight: 800; margin: 30px 0; font-variant-numeric: tabular-nums; letter-spacing: -2px; }
.mode-tags { display: flex; justify-content: center; gap: 10px; margin-bottom: 20px; }
.tag { padding: 8px 16px; border-radius: 16px; font-size: 13px; font-weight: 700; background: rgba(255,255,255,0.5); color: var(--text-sub); cursor: pointer; transition: 0.2s; }
.tag.active { background: var(--accent); color: white; transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.15); }
[data-theme="dark"] .tag { background: rgba(255, 255, 255, 0.1); color: rgba(255, 255, 255, 0.7); }
[data-theme="dark"] .tag.active { background: #ffffff; color: #000000; font-weight: 800; }

.course-palette { display: flex; overflow-x: auto; padding: 10px 5px 20px; gap: 10px; }
.course-chip { flex: 0 0 auto; height: 40px; padding: 0 20px; border-radius: 12px; background: #fff; border:none; box-shadow: 0 4px 8px rgba(0,0,0,0.05); cursor: pointer; font-weight: 700; color: var(--text-sub); display:flex; align-items:center; transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); }
.course-chip.active { color: #fff; transform: translateY(-4px) scale(1.05); box-shadow: 0 8px 16px rgba(0,0,0,0.15); outline: none; }
[data-theme="dark"] .course-chip { background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.15); color: var(--text-sub); box-shadow: none; }
[data-theme="dark"] .course-chip.active { border: none; color: #fff; box-shadow: 0 8px 20px rgba(0,0,0,0.4); }

.glass-table { padding: 15px; border-radius: 16px; overflow-x: auto; background: var(--glass-bg); backdrop-filter: blur(30px); -webkit-backdrop-filter: blur(30px); border: 1px solid var(--glass-border); box-shadow: var(--shadow-soft); transition: background 0.5s ease; }
.schedule-grid { display: grid; grid-template-columns: 40px repeat(7, minmax(45px, 1fr)); grid-template-rows: 20px repeat(28, 36px); gap: 4px; }
.grid-header, .grid-time { font-size: 11px; color: var(--text-main); font-weight: 800; opacity: 0.9; display: flex; align-items: center; justify-content: center; }
.grid-time { opacity: 0.8; font-weight: 700; padding-right: 2px; font-variant-numeric: tabular-nums; }

.grid-cell { background: transparent; border-radius: 8px; cursor: default; border: 1px solid transparent; transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1); transform: scale(1); }
body.painting-mode .grid-cell { cursor: pointer; background: rgba(0, 0, 0, 0.03); border: 1px dashed rgba(0, 0, 0, 0.1); transform: scale(0.92); border-radius: 6px; }
[data-theme="dark"] body.painting-mode .grid-cell { background: rgba(255, 255, 255, 0.05); border: 1px dashed rgba(255, 255, 255, 0.2); }
body.painting-mode .grid-cell:hover { background: rgba(0,0,0,0.06); transform: scale(0.95); }

.course-block { color: white; font-size: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; box-shadow: 0 4px 10px rgba(0,0,0,0.15); border-radius: 10px; cursor: pointer; z-index: 2; text-align: center; padding: 2px; line-height: 1.1; overflow: hidden; transform-origin: center; border-top: 1px solid rgba(255,255,255,0.3); transition: all 0.3s; }
.jelly-pop { animation: jelly-double 0.8s ease-in-out forwards; }
@keyframes jelly-double { 0% { transform: scale(0.9); opacity: 0; } 45% { transform: scale(1.04); opacity: 1; } 100% { transform: scale(1); } }

.library-shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--book-width), 1fr)); gap: 30px 15px; padding: 10px; }
.book-container { perspective: 600px; cursor: pointer; position: relative; display: flex; justify-content: center; }
.book { width: var(--book-width); height: var(--book-height); position: relative; transform-style: preserve-3d; transform: rotateY(-20deg) rotateX(5deg); transition: transform 0.4s; box-shadow: 8px 8px 20px rgba(0,0,0,0.2); border-radius: 2px 4px 4px 2px; }
.book-container:hover .book { transform: rotateY(0deg) scale(1.05) translateZ(20px); z-index: 10; }
.book-cover { position: absolute; width: 100%; height: 100%; background: #fff; border-radius: 2px 4px 4px 2px; background-size: cover; background-position: top center; display: flex; align-items: flex-end; overflow: hidden; }
.book-meta { width: 100%; background: rgba(255,255,255,0.9); padding: 5px; backdrop-filter: blur(5px); text-align: center; }
.book-title { font-size: calc(var(--book-width) * 0.1); font-weight: 800; color: #333; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; line-height: 1.2; }
.book-spine { position: absolute; top: 0; left: 0; width: 14px; height: 100%; background: #eee; transform: rotateY(-90deg) translateZ(-7px); border-radius: 2px 0 0 2px; background-image: linear-gradient(90deg, rgba(0,0,0,0.05), rgba(0,0,0,0.2)); }
.book-pages { position: absolute; top: 2px; right: 0; width: 12px; height: 96%; background: #fdfdfd; transform: rotateY(90deg) translateZ(calc(var(--book-width) * -1 + 7px)); box-shadow: inset 0 0 5px rgba(0,0,0,0.1); }

.add-book-cover { background: rgba(255, 255, 255, 0.05); border: 2px dashed var(--text-sub); display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-sub); font-weight: 700; }
.add-book-placeholder { box-shadow: none !important; }
body.has-custom-bg .add-book-cover { border-color: rgba(255,255,255,0.6); color: rgba(255,255,255,0.9); background: transparent; }

input[type=range] { -webkit-appearance: none; width: 100px; height: 4px; background: rgba(0,0,0,0.1); border-radius: 2px; outline: none; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; }

#loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); display: none; justify-content: center; align-items: center; z-index: 100; color: white; font-weight: 700; }
#glass-prompt-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(10px); z-index: 9999; display: none; flex-direction: column; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.3s; }
#glass-prompt-overlay.visible { opacity: 1; }
#glass-prompt-input { background: transparent; border: none; border-bottom: 2px solid rgba(255, 255, 255, 0.5); color: white; font-size: 32px; font-weight: 700; text-align: center; padding: 10px; width: 80%; outline: none; font-family: var(--font-stack); }
#glass-prompt-hint { color: rgba(255, 255, 255, 0.7); margin-top: 20px; font-size: 14px; }

#todo-empty-state { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 160px; height: 160px; border-radius: 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: pointer; animation: breathe 3s infinite ease-in-out; }
#todo-empty-state:hover { transform: translate(-50%, -50%) scale(1.05); background: rgba(255,255,255,0.8); }
.plus-icon { font-size: 50px; font-weight: 300; color: var(--accent); line-height: 1; }
.empty-text { font-size: 12px; color: var(--text-sub); margin-top: 10px; }
@keyframes breathe { 0%, 100% { box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1); } 50% { box-shadow: 0 15px 45px 0 rgba(31, 38, 135, 0.2); } }

/* To-Do List Container */
.todo-scroll-area { 
    height: 100%; 
    overflow-y: auto; 
    padding-bottom: 80px;
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    padding-top: 10px;
}

/* Card Styling */
.modern-todo-item { 
    background: var(--glass-bg); 
    margin-bottom: 12px; 
    padding: 12px 18px; 
    border-radius: 50px; 
    display: flex; 
    align-items: center; 
    gap: 12px; 
    border: 1px solid var(--glass-border); 
    animation: slide-up-fade 0.3s ease forwards; 
    /* 默认有动画 */
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.25s ease, opacity 0.2s; 
    cursor: grab;
    position: relative;
    width: 90%; 
    max-width: 360px; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.03);
}

.modern-todo-item:active { cursor: grabbing; }

/* 【核心修复】: 
   当容器拥有 .dragging-active 类时（即正在拖拽中），
   强制关闭所有子元素的过渡动画。
   这能彻底消除 DOM 重排时的“闪烁/鬼畜”现象。
*/
.todo-scroll-area.dragging-active .modern-todo-item {
    transition: none !important;
    animation: none !important;
}

/* 拖拽中的元素本身 */
.modern-todo-item.dragging {
    opacity: 0.5;
    transform: scale(1.05);
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 15px 30px rgba(0,0,0,0.15);
    z-index: 10;
    border-color: var(--accent);
    /* 让鼠标穿透拖拽元素，直接检测下方元素位置，这是解决抖动的第二重保障 */
    pointer-events: none; 
}

@keyframes slide-up-fade { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.todo-text {
    font-size: 16px;
    font-family: var(--font-stack);
    font-weight: 600;
    color: var(--text-main);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none; 
}

.todo-edit-input {
    background: transparent;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: var(--font-stack);
    color: inherit;
    width: 100%;
    font-weight: 600;
    display: none; 
    border-bottom: 2px solid var(--accent); 
    padding-bottom: 2px;
}

.modern-todo-item.editing .todo-text { display: none; }
.modern-todo-item.editing .todo-edit-input { display: block; }
.modern-todo-item.editing { cursor: text; background: rgba(255,255,255,0.9); }

.seamless-input { background: transparent; border: none; outline: none; font-size: 16px; font-family: var(--font-stack); color: inherit; width: 100%; font-weight: 600; }
.seamless-input::placeholder { color: var(--text-sub); opacity: 0.5; font-weight: 400; }

.modern-checkbox { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--text-sub); flex-shrink: 0; cursor: pointer; transition: 0.2s; }
.modern-todo-item.done .modern-checkbox { border-color: var(--accent); background: var(--accent); }
.modern-todo-item.done .todo-text { text-decoration: line-through; color: var(--text-sub); }

#todo-fab { position: absolute; bottom: 80px; right: 20px; width: 56px; height: 56px; border-radius: 50%; font-size: 30px; color: var(--accent); border: none; cursor: pointer; display: none; align-items: center; justify-content: center; transition: 0.2s; }
#todo-fab:active { transform: scale(0.9); }

#streak-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 5px; font-weight: 800; font-size: 14px; color: #FF7E67; background: var(--glass-bg); padding: 5px 12px; border-radius: 20px; border: 1px solid var(--glass-border); box-shadow: 0 4px 10px rgba(0,0,0,0.05); z-index: 200; transition: 0.3s; }

.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 15px 0; border-bottom: 1px solid rgba(0,0,0,0.05); }
[data-theme="dark"] .setting-item { border-bottom-color: rgba(255,255,255,0.1); }
.setting-label { font-size: 14px; font-weight: 700; }
.switch { position: relative; display: inline-block; width: 50px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.1); transition: .4s; border-radius: 34px; }
[data-theme="dark"] .slider { background-color: rgba(255,255,255,0.2); }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(22px); }

.num-input { width: 60px; padding: 5px; border-radius: 8px; border: 1px solid var(--glass-border); background: rgba(255,255,255,0.2); color: var(--text-main); text-align: center; font-family: var(--font-stack); font-weight: 700; }
[data-theme="dark"] .num-input { background: rgba(255,255,255,0.1); color: #fff; }
.app-footer { margin-top: 30px; text-align: center; font-size: 10px; color: var(--text-sub); opacity: 0.5; line-height: 1.6; font-weight: 600; }

body.idle-mode .glass-panel, body.idle-mode .modern-todo-item, body.idle-mode nav { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.05); box-shadow: none; transition: all 1.5s ease-in-out; }
[data-theme="dark"] body.idle-mode .glass-panel, [data-theme="dark"] body.idle-mode .modern-todo-item, [data-theme="dark"] body.idle-mode nav { background: rgba(0, 0, 0, 0.1); border-color: rgba(255, 255, 255, 0.02); }
body.idle-mode .todo-fab, body.idle-mode .btn { opacity: 0.5; transition: opacity 1.5s; }
.glass-panel, .modern-todo-item, nav, .btn { transition: all 0.3s ease-out; }

.focus-task-area { margin-top: 10px; width: 100%; display: flex; flex-direction: column; gap: 8px; align-items: center; padding-bottom: 20px; }
.focus-task-capsule { background: rgba(255, 255, 255, 0.4); border: 1px solid var(--glass-border); padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 700; color: var(--text-main); width: 100%; max-width: 280px; display: flex; align-items: center; gap: 10px; cursor: default; transition: all 0.2s; backdrop-filter: blur(10px); box-shadow: 0 4px 12px rgba(0,0,0,0.05); animation: slide-up-fade 0.3s ease forwards; }
.focus-task-capsule:hover { background: rgba(255, 255, 255, 0.5); }
.focus-task-capsule .mini-checkbox { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--text-sub); flex-shrink: 0; opacity: 0.6; }
.focus-task-capsule span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; text-align: left; }
[data-theme="dark"] .focus-task-capsule { background: rgba(255, 255, 255, 0.08); }