/* 习惯印记 - 主样式 */
:root {
  --bg: #0f1117;
  --bg-elev: #1a1d28;
  --bg-card: #232735;
  --bg-hover: #2d3142;
  --text: #e8eaf0;
  --text-dim: #8b91a3;
  --text-mute: #5a6072;
  --border: #2d3142;
  --accent: #6366f1;
  --accent-glow: #6366f166;
  --danger: #ef4444;
  --success: #22c55e;
  --warn: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --tab-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", "JetBrains Mono", Consolas, "Liberation Mono", monospace;
}

[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #eef0f6;
  --text: #1a1d28;
  --text-dim: #5a6072;
  --text-mute: #9aa0b2;
  --border: #e5e7eb;
  --accent: #6366f1;
  --accent-glow: #6366f144;
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* App 容器 */
#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
}

/* 顶部 Header */
.header {
  flex-shrink: 0;
  padding: 14px 16px 10px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.app-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.header-stats {
  display: flex;
  align-items: center;
  gap: 10px;
}
.streak-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, #ff8c42, #f59e0b);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  box-shadow: 0 2px 8px #f59e0b44;
}
.streak-badge .flame { font-size: 15px; }
.level-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
}
.exp-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  margin-top: 10px;
  overflow: hidden;
}
.exp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #8b5cf6);
  border-radius: 2px;
  transition: width 0.6s ease;
}

/* 页面容器 */
.page {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px calc(var(--tab-h) + var(--safe-bottom) + 16px);
  display: none;
  animation: fadeIn 0.25s ease;
}
.page.active { display: block; }

/* 底部 Tab */
.bottom-tabs {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 20;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--text-mute);
  transition: color 0.2s;
}
.tab-btn .tab-icon { font-size: 22px; }
.tab-btn.active { color: var(--accent); }
.tab-btn.active .tab-icon { transform: scale(1.1); transition: transform 0.2s; }

/* 通用卡片 */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* 按钮 */
.btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  transition: transform 0.1s, opacity 0.2s;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost {
  background: var(--bg-hover);
  color: var(--text);
}
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* 输入框 */
.input, .textarea, .select {
  width: 100%;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { resize: none; min-height: 60px; }

/* Modal */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--bg-elev);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 380px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: slideUp 0.25s ease;
}
.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 14px;
  text-align: center;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions .btn { flex: 1; }

/* Toast */
.toast {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--bg-card);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 24px;
  box-shadow: var(--shadow);
  z-index: 200;
  font-size: 14px;
  font-weight: 500;
  transition: transform 0.3s ease;
  max-width: 90%;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warn { border-left: 3px solid var(--warn); }

/* 大类网格 */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.cat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  position: relative;
  overflow: hidden;
  border: 2px solid transparent;
  transition: transform 0.1s, border-color 0.2s;
}
.cat-card:active { transform: scale(0.97); }
.cat-card .cat-icon { font-size: 28px; margin-bottom: 6px; }
.cat-card .cat-name { font-size: 14px; font-weight: 600; }
.cat-card .cat-count { font-size: 11px; color: var(--text-mute); margin-top: 2px; }
.cat-card .cat-stripe {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
}
.cat-card.done::after {
  content: '✓';
  position: absolute;
  top: 6px; right: 8px;
  font-size: 16px;
  color: var(--success);
  font-weight: 700;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes pop { 0% { transform: scale(0.8); opacity: 0; } 60% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }

/* 浮动快速打卡按钮 */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 20px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px var(--accent-glow), 0 2px 6px rgba(0,0,0,0.2);
  z-index: 30;
  transition: transform 0.2s;
  line-height: 1;
}
.fab:active { transform: scale(0.92); }
.fab.show { display: flex; animation: pop 0.3s ease; }
.fab::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid var(--bg);
  display: none;
}
.fab.alert::after { display: block; }
