:root {
  --bg: #f7f6f2;
  --fg: #1f1f1d;
  --muted: #6b6a66;
  --card: #ffffff;
  --line: #e4e2dc;
  --key: #ffffff;
  --key-active: #e9e7e0;
  --accent: #2f5bea;
  --danger: #c93a3a;
  --food: #e07a2f;
  --shopping: #2f6fe0;
  --subscription: #8553e0;
  --other: #5f6b7a;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --fg: #ececea;
    --muted: #9b9a95;
    --card: #1e2027;
    --line: #2c2f38;
    --key: #23262e;
    --key-active: #323642;
    --accent: #7c9bff;
    --danger: #ff7b7b;
    --food: #f09552;
    --shopping: #5b93f5;
    --subscription: #a37cf2;
    --other: #8a96a6;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.5em; margin: 0; }

.center {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- 登录 ---------- */
.auth {
  max-width: 360px;
  margin: 18vh auto 0;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth h1 { margin: 0; font-size: 26px; }
.auth p { margin: 0; }

.auth input {
  font: inherit;
  font-size: 17px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
}

.primary {
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
}

/* ---------- 主界面 ---------- */
main {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 32px;
}

.amount {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  gap: 6px;
  padding: 12px 4px 8px;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

.amount .cny { font-size: 24px; color: var(--muted); }
#amount { font-size: 52px; font-weight: 700; line-height: 1.1; }
#amount.zero { color: var(--muted); }

.meta {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.meta input {
  font: inherit;
  font-size: 16px; /* 16px 以上 iOS 不会自动放大页面 */
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  min-width: 0;
}

#note { flex: 1; }
#date { flex: 0 0 auto; max-width: 46%; }

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

.keypad button {
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--key);
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  user-select: none;
  -webkit-user-select: none;
}

.keypad button:active { background: var(--key-active); }

.hint {
  margin: 12px 0 6px;
  font-size: 13px;
  text-align: center;
}

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

.cats button {
  height: 64px;
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  user-select: none;
  -webkit-user-select: none;
  transition: opacity 0.15s, transform 0.05s;
}

.cats button:active { transform: scale(0.96); }
.cats button:disabled { opacity: 0.35; }
.cats .food { background: var(--food); }
.cats .shopping { background: var(--shopping); }
.cats .subscription { background: var(--subscription); }
.cats .other { background: var(--other); }

/* ---------- 统计 ---------- */
.stats, .list {
  margin-top: 28px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.month-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month-bar h2 { margin: 0; font-size: 17px; }

.month-bar button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  font-size: 22px;
  line-height: 1;
}

.month-bar button:disabled { opacity: 0.3; }

.total {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 14px 0 12px;
}

.total strong { font-size: 28px; font-variant-numeric: tabular-nums; }

.total { margin-bottom: 0; }
#month-left { margin: 2px 0 16px; text-align: right; font-size: 13px; }
.over { color: var(--danger); font-weight: 600; }
.bar-left { margin-top: 3px; font-size: 12px; text-align: right; }

.bar-row { margin-bottom: 12px; }
.bar-row:last-child { margin-bottom: 0; }

.bar-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 15px;
  margin-bottom: 4px;
}

.bar-head .name { display: flex; align-items: center; gap: 6px; }
.bar-head .dot { width: 10px; height: 10px; border-radius: 50%; }
.bar-head .num { font-variant-numeric: tabular-nums; }
.bar-head .pct { color: var(--muted); font-size: 13px; margin-left: 6px; }

.bar-track {
  height: 8px;
  border-radius: 4px;
  background: var(--line);
  overflow: hidden;
}

.bar-fill { height: 100%; border-radius: 4px; transition: width 0.25s; }

/* ---------- 明细 ---------- */
.list h2 { margin: 0 0 8px; font-size: 17px; }

.day {
  margin: 12px 0 4px;
  font-size: 13px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.item .tag {
  flex: 0 0 auto;
  padding: 2px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 13px;
}

.item .note {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 14px;
}

.item .num { font-variant-numeric: tabular-nums; font-weight: 600; }

.item .del {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
}

.foot {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

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

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-radius: 12px;
  background: #24262b;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  white-space: nowrap;
}

.toast .link { color: #9db4ff; }
.toast.error-toast { background: var(--danger); color: #fff; }
