:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --text: #15171c;
  --text-dim: #6b7280;
  --border: #e2e4ea;
  --accent: #6366f1;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #0f9d63;
  --card-checked: #e8f7ef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
}

[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --text: #e9ecf1;
  --text-dim: #9aa3b2;
  --border: #2a2f3a;
  --accent: #818cf8;
  --accent-text: #10121a;
  --danger: #f87171;
  --ok: #34d399;
  --card-checked: #14281f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 2px 10px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 15px; margin: 0 0 12px; }
p { margin: 0 0 12px; }

a { color: var(--accent); }

code {
  background: var(--surface-2);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  overflow-x: auto;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.muted { color: var(--text-dim); }
.small { font-size: 13px; }
.grow { flex: 1 1 auto; }
.hidden, [hidden] { display: none !important; }

/* ---------------------------------------------------------------- 布局 */

.view.centered {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px 16px 64px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel.narrow { width: 100%; max-width: 440px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 650; letter-spacing: .2px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.steps { margin: 0 0 12px; padding-left: 20px; color: var(--text-dim); }
.steps li { margin-bottom: 4px; }

/* -------------------------------------------------------------- 表单控件 */

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

input, select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
  outline: none;
}

input:focus-visible, select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

input[type="color"] {
  padding: 3px;
  height: 40px;
  cursor: pointer;
}

.fixed-sm { flex: 0 0 84px; }
.fixed-md { flex: 0 0 104px; }

form .row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

form .row.end { justify-content: flex-end; margin-bottom: 0; }
form .row.end > * { margin-bottom: 0; }

.btn {
  font: inherit;
  font-weight: 550;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 9px 14px;
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  transition: filter .15s, background .15s;
}

.btn:hover { filter: brightness(.97); }
[data-theme="dark"] .btn:hover { filter: brightness(1.15); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.link {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 6px;
  font-weight: 500;
}
.btn.block { width: 100%; margin-top: 4px; }
.btn.tiny { padding: 4px 8px; font-size: 12.5px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.alert {
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
  margin: 0 0 12px;
}
.alert.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.alert.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

/* ---------------------------------------------------------------- 选择器 */

.presets, .swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: -4px 0 12px;
}

.presets button {
  font: inherit;
  font-size: 17px;
  line-height: 1;
  padding: 6px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  cursor: pointer;
}

.swatches button {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}

/* ------------------------------------------------------------------ 统计 */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat .value { font-size: 24px; font-weight: 650; line-height: 1.2; }
.stat .value small { font-size: 14px; font-weight: 500; color: var(--text-dim); }
.stat .label { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

/* ------------------------------------------------------------------ 习惯 */

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

.habit {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--habit-color, var(--accent));
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

.habit.done { background: var(--card-checked); }
.habit.archived { opacity: .6; }

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

.habit-emoji { font-size: 22px; line-height: 1; }

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

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

.habit-meta { font-size: 12.5px; color: var(--text-dim); }

.check-btn {
  flex: 0 0 auto;
  font: inherit;
  font-weight: 600;
  min-width: 92px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--habit-color, var(--accent));
  background: transparent;
  color: var(--habit-color, var(--accent));
  cursor: pointer;
}

.check-btn[aria-pressed="true"] {
  background: var(--habit-color, var(--accent));
  color: #fff;
}

.habit-body { margin-top: 14px; }
.habit-body[hidden] { display: none; }

.week { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.week .dot {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  padding: 0;
  cursor: pointer;
  font-size: 10px;
  color: var(--text-dim);
}

.week .dot.on {
  background: var(--habit-color, var(--accent));
  border-color: transparent;
  color: #fff;
}

.week .dot.today { box-shadow: 0 0 0 2px color-mix(in srgb, var(--habit-color, var(--accent)) 45%, transparent); }
.week .dot.future { opacity: .35; cursor: not-allowed; }

.section-label { font-size: 12.5px; color: var(--text-dim); margin: 14px 0 8px; }

/* 热力图 */

.heatmap { overflow-x: auto; padding-bottom: 4px; }

.heatmap-months {
  display: flex;
  gap: 3px;
  height: 14px;
  margin-bottom: 3px;
}

.heatmap-months span {
  flex: 0 0 12px;
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
}

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

.heatmap-grid button {
  width: 12px;
  height: 12px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: pointer;
}

.heatmap-grid button.on {
  background: var(--habit-color, var(--accent));
  box-shadow: none;
}

.heatmap-grid button.today { box-shadow: inset 0 0 0 1.5px var(--text); }
.heatmap-grid button.future { opacity: .35; cursor: not-allowed; }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 28px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ------------------------------------------------------------------ 提示 */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 100;
  max-width: min(90vw, 420px);
}

@media (max-width: 560px) {
  .habit-head { flex-wrap: wrap; }
  .check-btn { width: 100%; }
  .topbar { flex-wrap: wrap; }
  #user-email { display: none; }
}
