/* ========== 基础 ========== */
:root {
  /* 默认：优雅淡紫 */
  color-scheme: light;
  --bg: #f5f3fa;
  --bg-soft: #ece8f4;
  --card: #ffffff;
  --card-2: #f3f0f9;
  --line: rgba(76, 60, 120, 0.10);
  --text: #2e2a3f;
  --muted: #7a7391;
  --topbar-bg: rgba(245, 243, 250, 0.92);
  --tabbar-bg: rgba(255, 255, 255, 0.94);
  --toast-bg: rgba(255, 255, 255, 0.97);
  --hero-a: #e6def5;
  --hero-b: #f8f6fc;
  --glow: #e4dcf5;
  --accent: #8b5cf6;
  --accent-deep: #6d28d9;
  --accent-2: #f59e0b;
  --good: #10b981;
  --bad: #ef4444;
  --radius: 16px;
}

[data-theme="warm"] {
  color-scheme: light;
  --bg: #faf6f0;
  --bg-soft: #f1e8da;
  --card: #fffdfa;
  --card-2: #f7f0e6;
  --line: rgba(120, 90, 60, 0.12);
  --text: #3d3229;
  --muted: #8a7a68;
  --topbar-bg: rgba(250, 246, 240, 0.92);
  --tabbar-bg: rgba(255, 253, 250, 0.94);
  --toast-bg: rgba(255, 253, 250, 0.97);
  --hero-a: #f7e6d2;
  --hero-b: #fcf8f2;
  --glow: #f3e4d0;
  --accent: #d97742;
  --accent-deep: #b45309;
  --accent-2: #e0a418;
  --good: #059669;
  --bad: #e11d48;
}

[data-theme="mint"] {
  color-scheme: light;
  --bg: #f2f8f5;
  --bg-soft: #e2efe8;
  --card: #ffffff;
  --card-2: #eef6f2;
  --line: rgba(20, 83, 60, 0.10);
  --text: #24382f;
  --muted: #6f8a7d;
  --topbar-bg: rgba(242, 248, 245, 0.92);
  --tabbar-bg: rgba(255, 255, 255, 0.94);
  --toast-bg: rgba(255, 255, 255, 0.97);
  --hero-a: #d6ecdf;
  --hero-b: #f6fbf8;
  --glow: #ddefe6;
  --accent: #10b981;
  --accent-deep: #047857;
  --accent-2: #f59e0b;
  --good: #059669;
  --bad: #ef4444;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-soft: #eaeef6;
  --card: #ffffff;
  --card-2: #f1f4fa;
  --line: rgba(15, 23, 42, 0.08);
  --text: #1f2937;
  --muted: #64748b;
  --topbar-bg: rgba(244, 246, 251, 0.92);
  --tabbar-bg: rgba(255, 255, 255, 0.94);
  --toast-bg: rgba(255, 255, 255, 0.97);
  --hero-a: #dbebfa;
  --hero-b: #f6f9fd;
  --glow: #e0ecfb;
  --accent: #0ea5e9;
  --accent-deep: #2563eb;
  --accent-2: #f59e0b;
  --good: #059669;
  --bad: #ef4444;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --card: #1a2438;
  --card-2: #223049;
  --line: rgba(148, 163, 184, 0.14);
  --text: #e8edf5;
  --muted: #93a1b8;
  --topbar-bg: rgba(15, 23, 42, 0.97);
  --tabbar-bg: rgba(20, 29, 47, 0.92);
  --toast-bg: rgba(30, 41, 59, 0.96);
  --hero-a: #16324f;
  --hero-b: #1a2438;
  --glow: #16233d;
  --accent: #38bdf8;
  --accent-deep: #2563eb;
  --accent-2: #f59e0b;
  --good: #34d399;
  --bad: #f87171;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* ========== 顶栏 ========== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
  background: linear-gradient(180deg, var(--topbar-bg) 80%, transparent);
  backdrop-filter: blur(8px);
}
.topbar h1 { font-size: 21px; font-weight: 700; letter-spacing: 0.5px; }
.topbar .sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); background: var(--bg-soft); transition: 0.15s;
}
.icon-btn:active { transform: scale(0.94); }

/* ========== 主区域 ========== */
#main { flex: 1; padding: 6px 14px calc(86px + env(safe-area-inset-bottom)); }
.view { display: none; animation: fadeIn 0.22s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 16px;
  margin-bottom: 12px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.field-label { font-size: 13.5px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
.field-label .muted { font-weight: 400; }

/* ========== 打卡页 ========== */
.checkin-hero {
  text-align: center;
  background: linear-gradient(135deg, var(--hero-a) 0%, var(--hero-b) 65%);
  padding: 20px 16px;
}
.hero-time { font-size: 34px; font-weight: 700; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.hero-hint { color: var(--muted); font-size: 13px; margin-top: 4px; }

.scale-row { display: flex; gap: 7px; }
.scale-item {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 2px 8px; border-radius: 12px;
  background: var(--bg-soft); border: 1.5px solid transparent;
  transition: 0.15s; font-size: 11px; color: var(--muted);
}
.scale-item .em { font-size: 22px; filter: grayscale(0.65) opacity(0.75); transition: 0.15s; }
.scale-item.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--text); }
.scale-item.on .em { filter: none; transform: scale(1.12); }
.scale-item.mood.on { border-color: var(--accent-2); background: rgba(245, 158, 11, 0.12); }
.scale-item:active { transform: scale(0.95); }

.chip-row { display: flex; gap: 8px; }
.chip-row.wrap { flex-wrap: wrap; }
.chip {
  padding: 7px 13px; border-radius: 999px;
  background: var(--bg-soft); color: var(--muted);
  font-size: 13px; border: 1.5px solid transparent;
  transition: 0.15s; white-space: nowrap;
}
.chip.on { color: var(--text); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.chip.pain.on { border-color: var(--bad); background: rgba(248, 113, 113, 0.14); }
.chip:active { transform: scale(0.95); }

textarea {
  width: 100%; resize: none;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); font-family: inherit; font-size: 14px;
  padding: 10px 12px; outline: none;
}
textarea:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%; padding: 15px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff; font-size: 16px; font-weight: 600; letter-spacing: 1px;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  transition: 0.15s; margin-top: 4px;
}
.btn-primary:active { transform: scale(0.98); }
.btn-primary.saved { background: linear-gradient(135deg, #34d399, #059669); box-shadow: 0 6px 18px rgba(5,150,105,0.35); }

/* ========== 今天页 ========== */
.day-summary { display: flex; gap: 8px; flex-wrap: wrap; }
.sum-pill {
  flex: 1; min-width: 90px; text-align: center;
  background: var(--bg-soft); border-radius: 12px; padding: 10px 6px;
}
.sum-pill .v { font-size: 19px; font-weight: 700; }
.sum-pill .k { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.timeline { position: relative; padding-left: 20px; }
.timeline::before {
  content: ""; position: absolute; left: 6px; top: 8px; bottom: 8px;
  width: 2px; background: var(--line); border-radius: 2px;
}
.t-item { position: relative; margin-bottom: 12px; }
.t-item::before {
  content: ""; position: absolute; left: -18px; top: 16px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}
.t-item.low::before { background: var(--bad); }
.t-card { padding: 12px 14px; margin-bottom: 0; }
.t-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 7px; }
.t-time { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.t-score { font-size: 13px; color: var(--muted); }
.t-score b { color: var(--text); font-size: 15px; }
.t-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.t-tag {
  font-size: 11.5px; padding: 3px 9px; border-radius: 999px;
  background: var(--bg-soft); color: var(--muted);
}
.t-tag.pain { background: rgba(248,113,113,0.15); color: var(--bad); }
.t-note { font-size: 13px; color: var(--muted); margin-top: 8px; }
.t-actions { display: flex; gap: 10px; margin-top: 9px; }
.t-actions button { font-size: 12px; color: var(--muted); padding: 3px 6px; border-radius: 6px; }
.t-actions button:active { background: var(--bg-soft); }

.empty { text-align: center; padding: 60px 0; color: var(--muted); }
.empty-icon { font-size: 42px; margin-bottom: 10px; }
.empty p { font-size: 15px; }
.empty .muted { font-size: 13px; margin-top: 4px; }

/* ========== 统计页 ========== */
.seg-row { display: flex; justify-content: center; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--bg-soft); border-radius: 12px; padding: 4px; }
.seg button { padding: 7px 22px; border-radius: 9px; font-size: 13.5px; color: var(--muted); transition: 0.15s; }
.seg button.on { background: var(--card-2); color: var(--text); font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat-card .v { font-size: 24px; font-weight: 700; }
.stat-card .v small { font-size: 13px; color: var(--muted); font-weight: 400; }
.stat-card .k { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat-card .trend-up { color: var(--good); font-size: 12px; }
.stat-card .trend-down { color: var(--bad); font-size: 12px; }

.chart-box { width: 100%; }
.chart-box svg { display: block; width: 100%; height: auto; }
.legend { display: flex; gap: 16px; justify-content: center; margin-top: 8px; font-size: 12px; color: var(--muted); }
.legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.legend .lg i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.factor-list { display: flex; flex-direction: column; gap: 9px; }
.factor-row { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.factor-row .name { width: 72px; color: var(--muted); flex-shrink: 0; }
.factor-row .bar { flex: 1; height: 9px; background: var(--bg-soft); border-radius: 5px; overflow: hidden; }
.factor-row .bar i { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--accent), var(--accent-deep)); }
.factor-row .cnt { width: 34px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ========== 洞察页 ========== */
.insight-card { border-left: 3px solid var(--accent); }
.insight-card.warn { border-left-color: var(--accent-2); }
.insight-card.bad { border-left-color: var(--bad); }
.insight-card.good { border-left-color: var(--good); }
.insight-card .i-title { font-weight: 600; font-size: 14.5px; margin-bottom: 6px; display: flex; align-items: center; gap: 7px; }
.insight-card .i-body { font-size: 13.5px; color: var(--muted); }
.insight-card .i-body b { color: var(--text); }

/* ========== 底部导航 ========== */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; z-index: 30;
  display: flex;
  background: var(--tabbar-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 4px; border-radius: 12px;
  color: var(--muted); font-size: 11px; transition: 0.15s;
}
.tab.on { color: var(--accent); }
.tab:active { transform: scale(0.94); }

/* ========== 弹窗 ========== */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.18s ease;
}
.modal {
  width: 100%; max-width: 560px;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 18px 20px calc(24px + env(safe-area-inset-bottom));
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { font-size: 17px; }
.modal-actions { display: flex; flex-direction: column; gap: 9px; margin: 14px 0; }
.btn-secondary {
  padding: 13px; border-radius: 12px;
  background: var(--bg-soft); color: var(--text);
  font-size: 14.5px; border: 1px solid var(--line); transition: 0.15s;
}
.btn-secondary:active { transform: scale(0.98); }
.btn-danger-ghost { padding: 12px; border-radius: 12px; color: var(--bad); font-size: 13.5px; }
.data-info { font-size: 12.5px; color: var(--muted); text-align: center; }

/* ========== Toast ========== */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--toast-bg); color: var(--text);
  padding: 10px 20px; border-radius: 999px; font-size: 13.5px;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toastIn 0.25s ease;
  max-width: 86vw; text-align: center;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ========== 桌面端 ========== */
@media (min-width: 640px) {
  body { background: radial-gradient(1200px 600px at 50% -100px, var(--glow) 0%, var(--bg) 55%); }
  .modal-mask { align-items: center; }
  .modal { border-radius: 20px; padding-bottom: 24px; }
}

/* ========== 表单控件 ========== */
input[type="time"], input[type="number"], input[type="text"], select {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); padding: 8px 10px; font-family: inherit; font-size: 14px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }

.setting-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 14px; }
.setting-row .seg button { padding: 5px 16px; font-size: 12.5px; }

/* ========== 生活页 ========== */
.add-row { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.add-row input[type="text"] { flex: 1; min-width: 0; }
.btn-add {
  padding: 8px 14px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 13.5px; white-space: nowrap;
  transition: 0.15s;
}
.btn-add:active { transform: scale(0.95); }

.water-counter { display: flex; align-items: center; justify-content: center; gap: 22px; padding: 4px 0; }
.water-num { font-size: 32px; font-weight: 700; text-align: center; }
.water-num small { font-size: 14px; }
.round-btn {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--bg-soft); border: 1px solid var(--line);
  font-size: 20px; color: var(--text); transition: 0.15s;
}
.round-btn:active { transform: scale(0.92); }
.progress { height: 8px; background: var(--bg-soft); border-radius: 5px; margin-top: 12px; overflow: hidden; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-deep)); border-radius: 5px; transition: width 0.3s; }
.sleep-info { margin-top: 10px; }

.life-item {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 2px; border-top: 1px solid var(--line); font-size: 13.5px;
}
.life-item:first-child { border-top: none; }
.life-item .del { color: var(--muted); padding: 4px 8px; border-radius: 8px; font-size: 13px; }
.life-item .del:active { background: var(--bg-soft); }

.week-row { display: flex; align-items: center; padding: 4px 0; font-size: 12px; }
.wk-name { width: 44px; flex-shrink: 0; color: var(--muted); }
.wk-cell { flex: 1; text-align: center; font-variant-numeric: tabular-nums; }
.wk-cell .zero { color: var(--muted); font-style: normal; opacity: 0.5; }

/* 自定义选项：+ 按钮与内联输入 */
.chip-add { border: 1.5px dashed var(--muted); background: transparent; opacity: 0.85; }
.chip-inline-input {
  width: 96px; border-radius: 999px !important;
  padding: 7px 13px !important; font-size: 13px !important;
}

/* ========== 快速记录悬浮按钮 ========== */
.fab {
  position: fixed; right: 18px; bottom: calc(88px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%; z-index: 25;
  background: linear-gradient(135deg, var(--accent), var(--accent-deep));
  color: #fff; font-size: 26px; line-height: 1;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: 0.15s;
}
.fab:active { transform: scale(0.92); }
@media (min-width: 640px) {
  .fab { right: calc(50% - 260px); }
}

/* ========== 饮水与同步 ========== */
.water-total { text-align: center; font-size: 32px; font-weight: 700; margin: 2px 0 4px; }
.water-total small { font-size: 14px; font-weight: 400; }
.quick-ml { padding: 6px 11px; font-size: 12.5px; }
.sync-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 2px; font-size: 15px; color: var(--accent);
}
