:root {
  --bg: #f4f5fa;
  --card: #ffffff;
  --text: #1c2230;
  --text-2: #6b7387;
  --line: #e9ecf3;
  --accent: #6c5ce7;
  --accent-soft: rgba(108, 92, 231, 0.12);
  --danger: #e5484d;
  --ok: #10b981;
  --ring-bg: #eef0f6;
  --cell: #eef0f6;
  --shadow: 0 10px 30px rgba(28, 34, 48, 0.08);
  --shadow-lg: 0 18px 50px rgba(28, 34, 48, 0.16);
  --heat-0: #eef0f6;
  --heat-1: rgba(108, 92, 231, 0.18);
  --heat-2: rgba(108, 92, 231, 0.4);
  --heat-3: rgba(108, 92, 231, 0.65);
  --heat-4: rgba(108, 92, 231, 0.95);
  --overlay: rgba(18, 21, 32, 0.5);
}

[data-theme="dark"] {
  --bg: #12141c;
  --card: #1c1f2a;
  --text: #eef0f7;
  --text-2: #99a1b6;
  --line: #2a2e3c;
  --accent: #8b7cf7;
  --accent-soft: rgba(139, 124, 247, 0.18);
  --ring-bg: #262a37;
  --cell: #262a37;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.5);
  --heat-0: #262a37;
  --heat-1: rgba(139, 124, 247, 0.22);
  --heat-2: rgba(139, 124, 247, 0.45);
  --heat-3: rgba(139, 124, 247, 0.68);
  --heat-4: rgba(139, 124, 247, 0.95);
  --overlay: rgba(0, 0, 0, 0.62);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background:
    radial-gradient(1200px 500px at 80% -10%, var(--accent-soft), transparent 60%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background 0.3s, color 0.3s;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

.hidden {
  display: none !important;
}

.app {
  max-width: 700px;
  margin: 0 auto;
  padding: 18px 16px 96px;
}

/* ===== 顶栏 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 2px 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px var(--accent-soft);
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1px;
}

.brand-text p {
  font-size: 12px;
  color: var(--text-2);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.icon-btn:hover {
  transform: translateY(-2px);
}

/* ===== 今日卡片 ===== */
.today-card {
  background: linear-gradient(135deg, var(--accent) 0%, #7c6cf0 55%, #a78bfa 100%);
  color: #fff;
  border-radius: 22px;
  padding: 24px 22px;
  display: flex;
  align-items: center;
  gap: 22px;
  box-shadow: 0 16px 40px rgba(108, 92, 231, 0.32);
  margin-bottom: 26px;
}

.ring-wrap {
  position: relative;
  flex: none;
  width: 120px;
  height: 120px;
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-bg,
.ring-fg {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.ring-bg {
  stroke: rgba(255, 255, 255, 0.22);
}

.ring-fg {
  stroke: #fff;
  transition: stroke-dashoffset 0.5s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-center span {
  font-size: 24px;
  font-weight: 800;
}

.ring-center small {
  font-size: 11px;
  opacity: 0.85;
}

.today-info {
  flex: 1;
  min-width: 0;
}

.today-info h2 {
  font-size: 21px;
  font-weight: 700;
  margin-bottom: 4px;
}

.today-info p {
  font-size: 13px;
  opacity: 0.92;
  margin-bottom: 14px;
}

.today-stats {
  display: flex;
  gap: 18px;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat b {
  font-size: 19px;
  font-weight: 800;
}

.stat span {
  font-size: 11px;
  opacity: 0.85;
}

/* ===== 列表 ===== */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-head h2 {
  font-size: 16px;
  font-weight: 700;
}

.ghost-btn {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 9px;
  background: var(--accent-soft);
  transition: transform 0.15s;
}

.ghost-btn:hover {
  transform: translateY(-1px);
}

.habit-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.habit-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--hc, var(--accent));
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s;
  animation: fadeIn 0.3s ease;
}

.habit-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.habit-card:active {
  transform: scale(0.99);
}

.habit-emoji {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--hc-soft, var(--accent-soft));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex: none;
}

.habit-info {
  flex: 1;
  min-width: 0;
}

.habit-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.habit-meta {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
}

.habit-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--cell);
  margin-top: 8px;
  overflow: hidden;
}

.habit-bar-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--hc, var(--accent));
  transition: width 0.4s ease;
}

.check-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 2px solid var(--hc, var(--accent));
  color: var(--hc, var(--accent));
  font-size: 21px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  background: transparent;
  transition: all 0.2s;
}

.check-btn:hover {
  transform: scale(1.06);
}

.check-btn.done {
  background: var(--hc, var(--accent));
  border-color: var(--hc, var(--accent));
  color: #fff;
  animation: pop 0.35s ease;
}

/* ===== 空状态 ===== */
.empty {
  text-align: center;
  padding: 48px 20px;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: 18px;
}

.empty-emoji {
  font-size: 44px;
  margin-bottom: 10px;
}

.empty-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.empty-sub {
  font-size: 13px;
  color: var(--text-2);
}

.footer {
  text-align: center;
  color: var(--text-2);
  font-size: 12px;
  margin-top: 30px;
}

/* ===== 悬浮按钮 ===== */
.fab {
  position: fixed;
  right: 22px;
  bottom: 26px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #fff;
  font-size: 30px;
  font-weight: 300;
  box-shadow: 0 12px 28px rgba(108, 92, 231, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  transition: transform 0.2s;
}

.fab:hover {
  transform: scale(1.08) rotate(90deg);
}

/* ===== 弹窗 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 60;
  animation: fade 0.18s ease;
}

.modal {
  background: var(--card);
  border-radius: 20px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px;
  position: relative;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

.modal-sm {
  max-width: 440px;
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.modal h4 {
  font-size: 13px;
  color: var(--text-2);
  font-weight: 600;
  margin: 18px 0 10px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 20px;
  color: var(--text-2);
  background: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.modal-close:hover {
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

.btn {
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  background: var(--cell);
  color: var(--text);
  transition: transform 0.15s, opacity 0.15s;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

.btn.danger {
  background: rgba(229, 72, 77, 0.12);
  color: var(--danger);
}

/* 习惯详情 */
.habit-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.habit-head .habit-emoji {
  width: 56px;
  height: 56px;
  font-size: 28px;
}

.habit-head-text h3 {
  font-size: 19px;
  margin: 0;
}

.habit-head-text p {
  font-size: 12px;
  color: var(--text-2);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.stat-box {
  background: var(--cell);
  border-radius: 14px;
  padding: 12px 6px;
  text-align: center;
}

.stat-box b {
  display: block;
  font-size: 18px;
  font-weight: 800;
}

.stat-box span {
  font-size: 11px;
  color: var(--text-2);
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}

.cal-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-2);
}

.cal-nav button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--cell);
  font-size: 16px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.cal-weekday {
  text-align: center;
  font-size: 11px;
  color: var(--text-2);
  padding: 4px 0;
}

.cal-day {
  aspect-ratio: 1;
  border-radius: 9px;
  background: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  position: relative;
  transition: transform 0.15s;
}

.cal-day:hover {
  transform: scale(1.08);
}

.cal-day.checked {
  background: var(--hc, var(--accent));
  color: #fff;
  font-weight: 700;
}

.cal-day.today {
  box-shadow: 0 0 0 2px var(--text);
}

.cal-day.blank {
  background: transparent;
}

.heat-wrap {
  overflow-x: auto;
  padding: 4px 0 2px;
}

.heat {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, 12px);
  grid-auto-columns: 12px;
  gap: 3px;
  width: max-content;
}

.heat-cell {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  background: var(--heat-0);
  cursor: default;
}

.heat-cell.l1 { background: var(--heat-1); }
.heat-cell.l2 { background: var(--heat-2); }
.heat-cell.l3 { background: var(--heat-3); }
.heat-cell.l4 { background: var(--heat-4); }

/* ===== 表单 ===== */
.form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
  margin-top: 8px;
}

.form input[type="text"],
.form textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--cell);
  color: var(--text);
  border-radius: 12px;
  padding: 11px 13px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border 0.2s;
}

.form input[type="text"]:focus,
.form textarea:focus {
  border-color: var(--accent);
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.emoji-opt {
  aspect-ratio: 1;
  border-radius: 10px;
  background: var(--cell);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s;
}

.emoji-opt:hover {
  transform: scale(1.1);
}

.emoji-opt.selected {
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent);
}

.color-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.color-opt {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  transition: transform 0.12s;
}

.color-opt:hover {
  transform: scale(1.15);
}

.color-opt.selected {
  box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--accent);
}

.form input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
}

/* ===== 设置 ===== */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.setting-row:last-of-type {
  border-bottom: none;
}

.setting-label {
  font-size: 14px;
  font-weight: 600;
}

.setting-value {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 8px;
}

.setting-actions {
  display: flex;
  gap: 8px;
}

.mini-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 7px 14px;
  border-radius: 10px;
}

.mini-btn.danger {
  color: var(--danger);
  background: rgba(229, 72, 77, 0.12);
}

.setting-tip {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 10px;
}

.version {
  text-align: center;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 14px;
}

.confirm-msg {
  font-size: 14px;
  color: var(--text-2);
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 20px);
  background: #232736;
  color: #fff;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 100;
  max-width: 86vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== 彩带 ===== */
.confetti {
  position: fixed;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  z-index: 120;
  pointer-events: none;
  animation: confetti-fly 0.9s ease-out forwards;
}

/* ===== 动画 ===== */
@keyframes pop {
  0% { transform: scale(0.6); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes confetti-fly {
  to {
    transform: translate(var(--dx), var(--dy)) rotate(540deg);
    opacity: 0;
  }
}

/* ===== 响应式 ===== */
@media (max-width: 480px) {
  .app {
    padding: 12px 12px 90px;
  }

  .today-card {
    padding: 18px 16px;
    gap: 16px;
  }

  .ring-wrap {
    width: 96px;
    height: 96px;
  }

  .ring-center span {
    font-size: 20px;
  }

  .today-stats {
    gap: 14px;
  }

  .stat b {
    font-size: 17px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .heat {
    grid-template-rows: repeat(7, 10px);
    grid-auto-columns: 10px;
    gap: 2px;
  }

  .heat-cell {
    width: 10px;
    height: 10px;
  }
}
