/* ===================== 设计变量 ===================== */
:root {
  --blue: #6c8cec;
  --blue-soft: #8aa6f5;
  --pink: #ff9ec8;
  --pink-soft: #ffc1dd;
  --grad: linear-gradient(135deg, #6c8cec 0%, #a78bfa 50%, #ff9ec8 100%);
  --grad-soft: linear-gradient(135deg, #eaf0ff 0%, #fdeef6 100%);

  --bg: #f7f9fe;
  --bg-2: #eef2fb;
  --card: #ffffff;
  --card-2: #fafbff;
  --text: #2b2f42;
  --text-2: #6b7090;
  --text-3: #9aa0bd;
  --border: #e9edf7;
  --shadow: 0 8px 24px rgba(108, 140, 236, 0.10);
  --shadow-sm: 0 2px 10px rgba(108, 140, 236, 0.08);
  --danger: #ff7a90;
  --warn: #ffa94d;
  --success: #4cc9a0;
  --radius: 22px;
  --radius-sm: 16px;
  --radius-xs: 12px;
  --sidebar-w: 25%;
  --sidebar-bg: var(--card);
}

[data-theme="dark"] {
  --bg: #14162a;
  --bg-2: #1b1e36;
  --card: #21243f;
  --card-2: #262a47;
  --text: #eef1ff;
  --text-2: #aab0d6;
  --text-3: #7b81a8;
  --border: #2f3354;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.3);
  --grad-soft: linear-gradient(135deg, #23284a 0%, #2b2140 100%);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  overflow: hidden;
  transition: background .3s, color .3s;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; font-size: 15px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* ===================== 布局 ===================== */
#app { display: flex; height: 100vh; height: 100dvh; }

  #sidebar {
    width: var(--sidebar-w);
    min-width: 220px;
    max-width: 320px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: calc(18px + env(safe-area-inset-top)) 14px calc(14px + env(safe-area-inset-bottom));
    gap: 8px;
    transition: transform .28s ease, background .3s;
    z-index: 30;
  }

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 14px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 13px;
  object-fit: cover;
  box-shadow: var(--shadow-sm);
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: var(--text-3); }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border-radius: 16px;
  color: var(--text-2); font-weight: 600; font-size: 14.5px;
  transition: background .2s, color .2s; text-align: left; width: 100%;
}
.nav-item .ico { font-size: 18px; width: 22px; text-align: center; }
.nav-item:hover { background: var(--bg-2); }
.nav-item.active { background: var(--grad-soft); color: var(--blue); }
.nav-item.active .ico { filter: none; }
.nav-item .badge { margin-left: auto; background: var(--pink); color: #fff; font-size: 11px; padding: 1px 8px; border-radius: 20px; }

.sidebar-footer { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.ghost-btn {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  padding: 9px; border-radius: 12px; background: var(--bg-2); color: var(--text-2); font-size: 13px; font-weight: 600;
}
.ghost-btn:active { transform: scale(.97); }

#content { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
  #topbar {
    display: flex; align-items: center; gap: 12px;
    padding: calc(14px + env(safe-area-inset-top)) 20px 14px; background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 20;
  }
#pageTitle { font-size: 18px; font-weight: 700; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { font-size: 20px; width: 40px; height: 40px; border-radius: 12px; background: var(--bg-2); display: grid; place-items: center; }
#menuToggle { display: none; }
.view { flex: 1; overflow-y: auto; padding: 20px; padding-bottom: calc(20px + env(safe-area-inset-bottom)); scroll-behavior: smooth; }

/* ===================== 响应式 ===================== */
@media (max-width: 860px) {
  #sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 78%; max-width: 300px;
    transform: translateX(-100%);
    box-shadow: var(--shadow);
  }
  #sidebar.open { transform: translateX(0); }
  #menuToggle { display: grid; }
  .view { padding: 16px 14px; }
  #topbar { padding: 12px 14px; }
}
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 25; display: none; }
.scrim.show { display: block; }

/* ===================== 卡片 / 通用组件 ===================== */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}
.card-title { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card-title .sub { font-size: 12px; color: var(--text-3); font-weight: 500; margin-left: auto; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 600px) { .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 420px) { .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; } }

.stat {
  background: var(--grad-soft); border-radius: var(--radius-sm); padding: 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat .label { font-size: 12px; color: var(--text-2); }
.stat .value { font-size: 24px; font-weight: 800; color: var(--blue); }
.stat .value.pink { color: var(--pink); }
.stat .delta { font-size: 11px; color: var(--text-3); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  background: var(--grad); color: #fff; box-shadow: var(--shadow-sm);
  transition: transform .12s, opacity .2s;
}
.btn:active { transform: scale(.96); }
.btn.secondary { background: var(--bg-2); color: var(--text); box-shadow: none; }
.btn.ghost { background: transparent; color: var(--blue); box-shadow: none; }
.btn.danger { background: var(--danger); }
.btn.sm { padding: 7px 12px; font-size: 13px; }
.btn.block { width: 100%; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
  background: var(--bg-2); color: var(--text-2); border: 1px solid transparent;
}
.chip.active { background: var(--grad-soft); color: var(--blue); border-color: var(--blue-soft); }
.chip.pink { background: #ffeaf3; color: var(--pink); }
.chip.blue { background: #eaf0ff; color: var(--blue); }

input, textarea, select {
  width: 100%; padding: 11px 13px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card-2); color: var(--text);
  outline: none; transition: border .2s, box-shadow .2s;
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(108,140,236,.15); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; font-weight: 600; }

.empty { text-align: center; color: var(--text-3); padding: 30px 10px; font-size: 14px; }
.empty .em { font-size: 34px; display: block; margin-bottom: 8px; }

/* 列表项 */
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-radius: 16px; background: var(--card-2); margin-bottom: 8px;
  border: 1px solid var(--border);
}
.list-item .body { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; font-size: 14.5px; }
.list-item .meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.list-item.done .title { text-decoration: line-through; color: var(--text-3); }
.list-item.overdue { background: #fff3e6; border-color: #ffd9a8; }
[data-theme="dark"] .list-item.overdue { background: #3a2c1a; border-color: #6b4a1f; }
.list-item.pinned { border-color: var(--pink); }

.checkbox {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border);
  display: grid; place-items: center; flex-shrink: 0; transition: .2s; color: #fff; font-size: 12px;
}
.checkbox.on { background: var(--success); border-color: var(--success); }
.list-item .actions { display: flex; gap: 4px; }
.icon-mini { width: 30px; height: 30px; border-radius: 9px; background: var(--bg-2); display: grid; place-items: center; font-size: 14px; }
.icon-mini:active { transform: scale(.92); }

.pill { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600; }
.pill.red { background: #ffe0e5; color: var(--danger); }
.pill.orange { background: #ffe9d3; color: var(--warn); }
.pill.green { background: #d7f5ea; color: var(--success); }
.pill.blue { background: #e3ebff; color: var(--blue); }
.pill.gray { background: var(--bg-2); color: var(--text-3); }

/* 日历 */
.cal { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head .m { font-weight: 700; font-size: 15px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--text-3); padding: 4px 0; }
.cal-cell {
  aspect-ratio: 1; border-radius: 11px; display: grid; place-items: center;
  font-size: 13px; position: relative; background: var(--card-2); color: var(--text); font-weight: 600;
}
.cal-cell.other { color: var(--text-3); opacity: .5; }
.cal-cell.today { background: var(--grad); color: #fff; }
.cal-cell.has::after { content: ""; position: absolute; bottom: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--pink); }
.cal-cell.today.has::after { background: #fff; }
.cal-cell.sel { outline: 2px solid var(--blue); outline-offset: -2px; }

/* 进度条 */
.progress { height: 9px; border-radius: 10px; background: var(--bg-2); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--grad); border-radius: 10px; transition: width .4s; }

/* 模态框 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20,22,42,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 700px) { .modal-mask { align-items: center; } }
.modal {
  background: var(--card); width: 100%; max-width: 520px; border-radius: 26px 26px 0 0;
  padding: 20px; max-height: 90vh; overflow-y: auto; animation: slideUp .25s ease;
}
@media (min-width: 700px) { .modal { border-radius: 22px; } }
@keyframes slideUp { from { transform: translateY(40px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { font-size: 22px; width: 34px; height: 34px; border-radius: 10px; background: var(--bg-2); }

/* Toast */
#toastRoot { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text); color: var(--card); padding: 10px 18px; border-radius: 30px;
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow); animation: pop .25s ease;
}
@keyframes pop { from { transform: translateY(-10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* 段控制 */
.seg { display: inline-flex; background: var(--bg-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { padding: 7px 14px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.seg button.on { background: var(--card); color: var(--blue); box-shadow: var(--shadow-sm); }

.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

.section-title { font-weight: 700; font-size: 15px; margin: 4px 0 12px; display: flex; align-items: center; gap: 8px; }
.muted { color: var(--text-3); }
.tiny { font-size: 12px; }

.tag-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; border:1px solid var(--border); border-radius: 12px; background: var(--card-2); }
.tag-input input { border: none; background: transparent; padding: 4px; flex: 1; min-width: 80px; }

/* 图表 */
.chart-wrap { width: 100%; overflow-x: auto; }
.chart-wrap svg { display: block; max-width: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; font-size: 12px; color: var(--text-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: middle; }

/* 月悦记 */
.cycle-card { background: var(--grad-soft); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.phase-bar { display: flex; border-radius: 12px; overflow: hidden; margin: 12px 0; }
.phase-bar > div { flex: 1; text-align: center; padding: 8px 2px; font-size: 11px; color: #fff; opacity: .55; }
.phase-bar > div.on { opacity: 1; font-weight: 700; }
.fb-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.fb-opt { padding: 7px 12px; border-radius: 10px; background: var(--card-2); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.fb-opt.on { background: var(--blue); color: #fff; border-color: var(--blue); }

.timer { font-size: 40px; font-weight: 800; text-align: center; color: var(--blue); font-variant-numeric: tabular-nums; }
.link-card { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--border); margin-bottom: 8px; }
.link-card .em { font-size: 20px; }

/* 备份抽屉 */
.drawer-mask { position: fixed; inset: 0; background: rgba(20,22,42,.45); z-index: 60; display: flex; justify-content: flex-end; }
.drawer { width: 100%; max-width: 380px; background: var(--card); height: 100%; padding: 20px; overflow-y: auto; animation: slideL .25s ease; }
@keyframes slideL { from { transform: translateX(40px); } to { transform: translateX(0); } }

.hide-scroll::-webkit-scrollbar { display: none; }
.fade-in { animation: fadeIn .3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 课程表图片导入 */
.upload-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 34px 20px; margin-bottom: 14px; cursor: pointer;
  border: 2px dashed var(--border); border-radius: 22px;
  background: var(--card); color: var(--text-2); transition: border-color .2s, background .2s, transform .15s;
}
.upload-zone:active { transform: scale(.99); }
.upload-zone:hover { border-color: var(--blue); background: var(--card-2); }
.upload-zone .up-icon { font-size: 38px; }
.upload-zone .up-title { font-size: 16px; font-weight: 700; color: var(--text); }
.upload-zone .up-sub { font-size: 12.5px; color: var(--text-3); }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.photo-card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 10px; box-shadow: var(--shadow-sm); }
.photo-thumb { width: 100%; height: 150px; object-fit: cover; border-radius: 12px; cursor: pointer; display: block; }
.photo-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.photo-card input { margin-top: 8px; }

.lightbox { position: fixed; inset: 0; background: rgba(15,17,33,.9); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px; cursor: zoom-out; animation: fadeIn .2s ease; }
.lightbox-img { max-width: 100%; max-height: 100%; border-radius: 16px; object-fit: contain; }

/* ===================== 新增：能量补给站 / 设置 / 自定义 ===================== */
/* 每日能量补给站（放大 + 动态） */
.energy-card {
  position: relative; overflow: hidden;
  background: var(--grad); background-size: 220% 220%; color: #fff;
  border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
  animation: gradShift 9s ease infinite;
}
@keyframes gradShift { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
.energy-card::before {
  content: ""; position: absolute; left: -40px; bottom: -50px;
  width: 150px; height: 150px; border-radius: 50%;
  background: rgba(255,255,255,.14);
}
.energy-card::after {
  content: ""; position: absolute; right: -30px; top: -30px;
  width: 120px; height: 120px; border-radius: 50%;
  background: rgba(255,255,255,.12);
}
/* 漂浮的闪光点 */
.energy-card .spark {
  position: absolute; right: 18px; top: 14px; z-index: 1;
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(255,255,255,0) 70%);
  box-shadow: 0 0 12px 4px rgba(255,255,255,.5);
  animation: sparkFloat 3.2s ease-in-out infinite;
}
@keyframes sparkFloat { 0%,100% { transform: translateY(0) scale(1); opacity: .8; } 50% { transform: translateY(-8px) scale(1.25); opacity: 1; } }
.energy-card .h { font-size: 12px; opacity: .92; display: flex; align-items: center; gap: 6px; position: relative; z-index: 1; }
.energy-card .q { font-size: 15.5px; font-weight: 700; line-height: 1.55; margin-top: 8px; position: relative; z-index: 1; transition: opacity .28s ease; }
.energy-card .q.fade { opacity: 0; }
.energy-card .shuffle { position: absolute; left: 16px; bottom: 14px; z-index: 1; background: rgba(255,255,255,.22); color: #fff; border-radius: 20px; padding: 6px 12px; font-size: 12px; font-weight: 600; }
.energy-card .shuffle:active { transform: scale(.95); }
/* 放大版 */
.energy-card.big { padding: 26px 26px 30px; }
.energy-card.big .h { font-size: 13px; }
.energy-card.big .q { font-size: 19px; line-height: 1.7; min-height: 66px; letter-spacing: .2px; }
.energy-card.big .shuffle { left: auto; right: 16px; bottom: 16px; padding: 8px 14px; font-size: 12.5px; }

/* 习惯 chip 配图按钮 */
.chip-wrap { display: inline-flex; align-items: center; gap: 2px; }
.cam {
  width: 26px; height: 26px; border-radius: 50%; background: var(--grad-soft);
  color: var(--blue); display: grid; place-items: center; font-size: 13px; flex-shrink: 0;
  border: 1px solid var(--blue-soft);
}
.cam:active { transform: scale(.92); }

/* 设置预览 / 色板 */
.set-prev { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.set-prev .logo { width: 46px; height: 46px; border-radius: 14px; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 20px; overflow: hidden; flex-shrink: 0; }
.set-prev .logo img { width: 100%; height: 100%; object-fit: cover; }
.set-prev .name { font-weight: 700; font-size: 15px; }
.set-prev .sub { font-size: 11px; color: var(--text-3); }

.swatch-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 14px; }
.swatch { width: 40px; height: 40px; border-radius: 13px; border: 2px solid transparent; cursor: pointer; box-shadow: var(--shadow-sm); }
.swatch.on { border-color: var(--text); transform: scale(1.06); }
.color-fields { display: flex; gap: 12px; flex-wrap: wrap; }
.color-fields label { flex: 1; min-width: 120px; }
.color-fields .cp { height: 42px; padding: 4px; cursor: pointer; }

/* 可删除标签 */
.x-chip { position: relative; }
.x-chip > .x {
  position: absolute; top: -7px; right: -7px; width: 18px; height: 18px;
  border-radius: 50%; background: var(--danger); color: #fff; font-size: 11px;
  display: none; place-items: center; line-height: 1;
}
.x-chip:active > .x, .x-chip.show-x > .x { display: grid; }

/* 缩略图 */
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; border: 1px solid var(--border); flex-shrink: 0; }
.thumb-wrap { position: relative; display: inline-block; }
.thumb-wrap .x { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 11px; display: grid; place-items: center; }

/* 平台选择（月悦记外链） */
.plat-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.plat { padding: 7px 13px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); font-weight: 600; }
.plat.on { background: var(--grad-soft); border-color: var(--blue); color: var(--blue); }
.plat.disabled { opacity: .5; }

/* 日期 / 时间输入增强圆角 */
input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"], input[type="week"] {
  border-radius: 14px;
}

/* 自定义食物/习惯管理行 */
.manage-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 12px; background: var(--card-2); margin-bottom: 6px; }
.manage-row .t { flex: 1; font-size: 13.5px; font-weight: 600; }

/* 课表批量导入文本域 */
.import-help { font-size: 12px; color: var(--text-3); background: var(--bg-2); border-radius: 10px; padding: 8px 10px; margin-bottom: 10px; line-height: 1.5; }

