:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #1f2533;
  --muted: #8a93a6;
  --primary: #4c6ef5;
  --primary-d: #3b5bdb;
  --yuwen: #e8590c;   /* 语文 */
  --shuxue: #1c7ed6;  /* 数学 */
  --yingyu: #2f9e44;  /* 英语 */
  --qita: #868e96;    /* 其他 */
  --line: #e7eaf1;
  --ok: #2f9e44;
  --shadow: 0 2px 10px rgba(20,30,60,.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 540px;
  margin: 0 auto;
  padding-bottom: 220px;
  font-size: 15px;
}

/* 顶栏 */
.topbar { background: linear-gradient(135deg, #5c7cfa, #4c6ef5); color: #fff; padding: 14px 16px 10px; }
.topbar-row { display: flex; align-items: center; justify-content: space-between; }
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; }
.icon-btn { background: rgba(255,255,255,.2); border: none; color: #fff; border-radius: 10px; width: 36px; height: 36px; font-size: 18px; cursor: pointer; }
.date-nav { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.date-nav input[type=date] { flex: 1; border: none; border-radius: 10px; padding: 8px 10px; font-size: 15px; color: var(--text); background: #fff; }
.today-btn { background: rgba(255,255,255,.25); border: none; color: #fff; border-radius: 10px; padding: 8px 12px; font-size: 14px; cursor: pointer; }

/* 科目筛选 */
.subject-tabs { display: flex; gap: 8px; padding: 12px 16px 4px; overflow-x: auto; }
.subj-tab { flex: 0 0 auto; border: 1.5px solid var(--line); background: var(--card); border-radius: 20px; padding: 6px 14px; font-size: 14px; cursor: pointer; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.subj-tab .badge { background: var(--line); color: var(--text); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; }
.subj-tab.active { color: #fff; border-color: transparent; }
.subj-tab.active.语文 { background: var(--yuwen); }
.subj-tab.active.数学 { background: var(--shuxue); }
.subj-tab.active.英语 { background: var(--yingyu); }
.subj-tab.active.其他 { background: var(--qita); }
.subj-tab.active .badge { background: rgba(255,255,255,.3); color: #fff; }

/* 进度 */
.progress-wrap { display: flex; align-items: center; gap: 10px; padding: 8px 16px 4px; }
.progress-bar { flex: 1; height: 8px; background: var(--line); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg,#51cf66,#2f9e44); transition: width .3s; }
.progress-text { font-size: 13px; color: var(--muted); min-width: 52px; text-align: right; }

/* 任务列表 */
.task-list { padding: 8px 16px; }
.task-item { background: var(--card); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap; }
.task-item.done .task-content { text-decoration: line-through; color: var(--muted); }
.check { width: 32px; height: 32px; border-radius: 50%; border: 2.5px solid var(--muted); flex: 0 0 auto; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; margin-top: 2px; position: relative; }
/* 透明扩展热区：把可点击范围向外扩 ~9px，手机上更容易点中、更灵敏 */
.check::before { content: ''; position: absolute; inset: -9px; border-radius: 50%; }
.task-item.done .check { background: var(--ok); border-color: var(--ok); }
.task-body { flex: 1; min-width: 0; }
.task-content { font-size: 15px; line-height: 1.4; word-break: break-word; }
.task-meta { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; align-items: center; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 8px; font-weight: 600; }
.tag.语文 { background: #fff0e6; color: var(--yuwen); }
.tag.数学 { background: #e7f1ff; color: var(--shuxue); }
.tag.英语 { background: #e6f7eb; color: var(--yingyu); }
.tag.其他 { background: #f0f1f4; color: var(--qita); }
.task-actions { display: flex; flex-direction: column; gap: 8px; }
.mini-btn { background: none; border: none; cursor: pointer; font-size: 16px; color: var(--muted); padding: 2px; }
.mini-btn.running { color: var(--primary); animation: pulseTimer 1.1s ease-in-out infinite; }
@keyframes pulseTimer { 0%,100% { opacity: 1; } 50% { opacity: .45; } }

/* 「开始作业」整卡宽度按钮：放在卡片底部，手机上大靶区、好点 */
.task-foot { flex-basis: 100%; margin-top: 10px; }
.start-btn { width: 100%; border: 1.5px solid var(--primary); background: #eef2ff; color: var(--primary-d); border-radius: 11px; padding: 12px; font-size: 15px; font-weight: 700; cursor: pointer; -webkit-tap-highlight-color: transparent; font-family: inherit; letter-spacing: .5px; }
.start-btn:active { transform: translateY(1px); }
.start-btn .timer-val { font-variant-numeric: tabular-nums; }
.start-btn.running { background: var(--primary); color: #fff; border-color: var(--primary); animation: pulseBtn 1s ease-in-out infinite; }
@keyframes pulseBtn { 0%,100% { box-shadow: 0 0 0 0 rgba(76,110,245,.45); } 50% { box-shadow: 0 0 0 6px rgba(76,110,245,0); } }

/* 任务下方的时间行：运行中走秒 / 完成时间 / 已计时长 */
.task-time { margin-top: 6px; font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; line-height: 1.4; }
.t-timer { color: var(--primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.t-done { color: var(--ok); }
.t-dur { color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 14px; }

/* 添加区 */
.add-zone { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 540px; background: var(--card); border-top: 1px solid var(--line); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px rgba(20,30,60,.08); }
.panel { display: flex; flex-direction: column; gap: 10px; }
.panel.hidden, .hidden { display: none !important; }
textarea, input, select { width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px; font-size: 15px; font-family: inherit; color: var(--text); background: #fff; resize: none; }
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--primary); }
.add-row { display: flex; gap: 8px; }
.add-row select { flex: 0 0 110px; }
.primary-btn { background: var(--primary); color: #fff; border: none; border-radius: 10px; padding: 10px 18px; font-size: 15px; font-weight: 600; cursor: pointer; }
.primary-btn.block { width: 100%; }
.ghost-btn { background: #fff; color: var(--muted); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 18px; font-size: 15px; cursor: pointer; }
/* 常驻「添加作业」触发按钮：默认显示，点击后展开输入框 */
.add-trigger { width: 100%; background: var(--primary); color: #fff; border: none; border-radius: 12px; padding: 14px; font-size: 16px; font-weight: 600; cursor: pointer; box-shadow: 0 6px 18px rgba(58,110,255,.28); }
.add-trigger:active { transform: translateY(1px); }

/* 解析预览 */
.parse-preview { border: 1px dashed var(--line); border-radius: 12px; padding: 10px; max-height: 200px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.pv-item { display: flex; gap: 8px; align-items: center; }
.pv-item input[type=checkbox] { width: 22px; height: 22px; flex: 0 0 auto; }
.pv-item .pv-text { flex: 1; font-size: 14px; word-break: break-word; }
.pv-item select { flex: 0 0 84px; padding: 6px; font-size: 13px; }

/* 弹窗 */
.modal { position: fixed; inset: 0; background: rgba(20,30,60,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal-card { background: #fff; border-radius: 16px; padding: 18px; width: 100%; max-width: 380px; }
.modal-card h3 { margin: 0 0 12px; }
.edit-row { display: flex; gap: 10px; margin: 10px 0; }
.edit-row label, .edit-date { flex: 1; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.edit-date { margin: 10px 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; margin: 0 0 10px; }
.switch-row { display: flex; align-items: center; gap: 10px; font-size: 14px; margin: 8px 0 10px; cursor: pointer; }
.switch-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); flex: none; }
.modal-card { max-height: 86vh; overflow-y: auto; }
#customKwInput { font-size: 13px; line-height: 1.6; resize: vertical; }

/* 扫码区 */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 12px; background: #f7f8fa; border-radius: 12px; margin-bottom: 6px; }
.qr-box img { width: 160px; height: 160px; border-radius: 8px; background: #fff; }
.qr-url { font-size: 11px; color: var(--muted); word-break: break-all; text-align: center; line-height: 1.5; }

/* 同步状态条 */
.sync-state { font-size: 11px; text-align: center; padding: 3px 0 1px; color: var(--muted); letter-spacing: .2px; }
.sync-state.ok { color: #16a34a; }
.sync-state.offline { color: #d97706; font-weight: 600; }

/* toast */
.toast { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); background: #1f2533; color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 100; box-shadow: 0 4px 16px rgba(0,0,0,.2); }

/* ---- 完成作业的鼓励动画 ---- */
.confetti { position: fixed; width: 9px; height: 9px; border-radius: 2px; z-index: 200; pointer-events: none; animation: confettiFly .85s cubic-bezier(.2,.6,.3,1) forwards; }
@keyframes confettiFly {
  0%   { transform: translate(-50%,-50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.35) rotate(var(--rot)); opacity: 0; }
}
.praise-bubble {
  position: fixed; transform: translate(-50%,-50%); z-index: 201; pointer-events: none; white-space: nowrap;
  background: linear-gradient(135deg,#ffd43b,#ff922b); color: #fff; font-weight: 800;
  padding: 8px 18px; border-radius: 22px; font-size: 16px;
  box-shadow: 0 6px 20px rgba(255,146,43,.4); animation: praisePop 1.1s ease-out forwards;
}
@keyframes praisePop {
  0%   { transform: translate(-50%,-50%) scale(.4); opacity: 0; }
  22%  { transform: translate(-50%,-50%) scale(1.12); opacity: 1; }
  70%  { transform: translate(-50%,-115%) scale(1); opacity: 1; }
  100% { transform: translate(-50%,-160%) scale(.9); opacity: 0; }
}

/* ---- 任务项删除动画（先折叠淡出再移除） ---- */
.task-item { overflow: hidden; transition: opacity .3s ease, transform .3s ease, height .3s ease, padding .3s ease, margin .3s ease; }
.task-item.removing { opacity: 0; transform: translateX(64px) scale(.95); height: 0 !important; padding-top: 0; padding-bottom: 0; margin-bottom: 0; box-shadow: none; }

/* 顶栏操作区：用户徽章 + 登出/设置按钮 */
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.user-badge { font-size: 13px; color: #fff; opacity: .92; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 登录 / 注册覆盖层 */
.auth-layer { position: fixed; inset: 0; background: linear-gradient(135deg, #5c7cfa, #4c6ef5); display: flex; align-items: center; justify-content: center; z-index: 300; padding: 24px; }
.auth-layer.hidden { display: none; }
.auth-card { background: #fff; border-radius: 18px; padding: 26px 22px; width: 100%; max-width: 360px; box-shadow: 0 12px 40px rgba(20,30,60,.25); }
.auth-card h2 { margin: 0 0 8px; font-size: 20px; color: var(--text); }
.auth-card .hint { margin: 0 0 18px; }
.auth-card input { margin-bottom: 12px; font-size: 16px; padding: 12px; }
.auth-card .primary-btn.block { margin-bottom: 10px; padding: 13px; font-size: 16px; }
.auth-switch { background: none; border: none; color: var(--primary); font-size: 14px; cursor: pointer; width: 100%; padding: 6px; }
