/* =====================================================================
   记账 app.css — 设计 token、全域、App 壳、Tab Bar、浮层、对话框、Toast
   ---------------------------------------------------------------------
   数值来源（Task 8 查证）：
   - [apple-skills:hig typography.md「iOS, iPadOS Dynamic Type sizes · Large (default)」]
       Large Title 34/41 · Title 3 20/25 · Headline 17/22 semibold · Body 17/22
       Subhead 15/20 · Footnote 13/18 · Caption 1 12/16（size/leading，单位 pt）
       Large Title 的 emphasized weight 为 Bold。
   - [apple-skills:hig accessibility.md / buttons.md] iOS 最小点击区 44x44 pt。
   - [apple-skills:hig color.md「System colors」表，iOS 26 快照]
       Blue  light rgb(0,136,255)  dark rgb(0,145,255)（仅作历史参考：强调色现已改为 ink，不再使用 systemBlue）
       Green light rgb(52,199,89)  dark rgb(48,209,88)
       Red   light rgb(255,56,60)  dark rgb(255,66,69)
   - [apple-skills:hig color.md] 语义色名称（label / secondaryLabel / tertiaryLabel /
       separator / systemGroupedBackground / secondarySystemGroupedBackground / systemFill）
       有列出，但没有给数值；下面的数值是 UIKit 公开的标准值（凭既有知识，skill 无法查证）。
   - Tab Bar 高度：apple-skills:hig tab-bars.md 只有 tvOS（68pt）数值，iOS 没有；
       这里用 UIKit 传统 iPhone Tab Bar 49pt（凭既有知识，skill 无法查证）。
   - [apple-hig-skills:hig-foundations] 用系统语义色、支援深色模式、Dynamic Type、
       Reduce Motion；[hig-components-layout] iPhone 3–5 个同级分页用底部 Tab Bar；
       [hig-platforms] iOS 触控优先、单手操作、尊重安全区。
   - [apple-skills:hig alerts.md] 取消在 leading、主要动作在 trailing；不要把取消设成默认。
   - [apple-skills:hig action-sheets.md] 取消按钮放在最下面；破坏性动作用 destructive 样式。
   - 卡片 / 抽屉圆角：HIG 未给数值，结余卡与抽屉 / sheet 现用 30pt 大圆角；--radius-card 12px 仅留给小型提示条 / 分组块。
   ===================================================================== */

/* ---------- 1. 设计 token：颜色（浅色，雾蓝主题） ----------
   每个 token 必须同时出现在 :root、@media dark 的 :root:not([data-theme="light"])、:root[data-theme="dark"]。 */
:root {
  color-scheme: light;

  /* 整页「晨雾」渐变：浅蓝 → 薄荷绿（0% / 30% / 65% / 100%） */
  --sky-top: #CFE3EF;
  --sky-mid: #D4EAEE;
  --sky-low: #D9F0E8;
  --sky-bottom: #E4F6EE;
  --ink: #0A0A0B;
  --ink-2: rgba(10, 12, 18, 0.65);
  --ink-3: rgba(10, 12, 18, 0.32);
  --glass: rgba(255, 255, 255, 0.52);
  --glass-edge: rgba(255, 255, 255, 0.9);
  --glass-shade: rgba(40, 60, 90, 0.10);
  --drawer: #FFFFFF;
  --hairline: rgba(10, 12, 18, 0.08);
  --btn-bg: #0A0A0B;
  --btn-fg: #FFFFFF;
  --on-red: #FFFFFF;                /* 红底上的字（滑动删除等），各主题都是白 */
  --red-text: #D70015;              /* 红字专用（底色为抽屉 / ink-tint 时 ≥4.5:1） */
  --income: #157A35;
  --red: rgb(255, 56, 60);          /* systemRed */
  --track: rgba(10, 12, 18, 0.10);
  --glass-sheen: rgba(255, 255, 255, 0.18);
  /* 结余卡后面的光球（静态 radial-gradient）。深色版：光球透明度 ×0.5、卡片左上玻璃 .10、次要字 .95，
     是为了让压在光球上的字仍 ≥4.5:1（tests/contrast.test.js 锁住）。深色余量很小（约 4.6），
     调亮光球、玻璃或调暗次要字都必须先跑测试 */
  --orb-1: rgba(110, 185, 255, 0.62);
  --orb-2: rgba(100, 220, 180, 0.58);
  --orb-3: rgba(90, 205, 215, 0.5);
  --orb-4: rgba(150, 200, 250, 0.45);
  /* 结余卡玻璃：半透明底、渐层反光边（左上亮 → 右下暗）、内阴影＋投影 */
  --card-glass-1: rgba(255, 255, 255, 0.78);
  --card-glass-2: rgba(255, 255, 255, 0.48);
  --card-rim-1: rgba(255, 255, 255, 1);
  --card-rim-2: rgba(255, 255, 255, 0.35);
  --card-rim-3: rgba(255, 255, 255, 0.08);
  --card-rim-4: rgba(80, 90, 140, 0.4);
  --card-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.9), inset 0 -12px 24px -16px rgba(60, 70, 120, 0.3),
    0 24px 44px -20px rgba(70, 60, 140, 0.42), 0 4px 12px -6px rgba(40, 50, 90, 0.16);
  --card-ink-2: rgba(10, 12, 18, 0.65);   /* 卡片上的次要字（深色版较亮，压在光球上仍 ≥4.5:1） */
  --tab-glass: rgba(255, 255, 255, 0.72);
  --tab-off: rgba(10, 12, 18, 0.6);

  --fill: rgba(120, 120, 128, 0.2);
  --ink-tint: rgba(10, 12, 18, 0.08);
  --ink-sel: rgba(10, 12, 18, 0.16);
  --press-bg: #F1F1F3;
  --separator: rgba(10, 12, 18, 0.14);
  --bar-material: rgba(207, 227, 239, 0.94);   /* ≈ sky-top：子页面导航条与状态栏同色 */
  --alert-material: rgba(242, 242, 242, 0.86);
  --sheet-material: rgba(242, 242, 242, 0.86);
  --sheet-cancel-bg: #FFFFFF;
  --dim: rgba(0, 0, 0, 0.2);
  --seg-track: rgba(118, 118, 128, 0.12);
  --grabber: rgba(60, 60, 67, 0.3);

  /* 旧名别名：未改到的旧样式自动跟上新 token */
  --label: var(--ink);
  --secondary-label: var(--ink-2);
  --tertiary-label: var(--ink-3);
  --bg-grouped-secondary: var(--drawer);
}

/* ---------- 1b. 设计 token：颜色（深色，两块内容必须一致） ---------- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --sky-top: #132230; --sky-mid: #11232A; --sky-low: #0F2222; --sky-bottom: #0B1A17;
    --ink: #F4F6F8; --ink-2: rgba(235, 240, 248, 0.66); --ink-3: rgba(235, 240, 248, 0.34);
    --glass: rgba(255, 255, 255, 0.07); --glass-edge: rgba(255, 255, 255, 0.16); --glass-shade: rgba(0, 0, 0, 0.35);
    --drawer: #1A1D23; --hairline: rgba(255, 255, 255, 0.08);
    --btn-bg: #F4F6F8; --btn-fg: #0A0A0B; --on-red: #FFFFFF; --red-text: #FF6B6F;
    --income: #4CD07A; --red: rgb(255, 66, 69);
    --track: rgba(255, 255, 255, 0.14);
    --glass-sheen: rgba(255, 255, 255, 0.18);
    --orb-1: rgba(110, 185, 255, 0.31); --orb-2: rgba(100, 220, 180, 0.29);
    --orb-3: rgba(90, 205, 215, 0.25); --orb-4: rgba(150, 200, 250, 0.225);
    --card-glass-1: rgba(255, 255, 255, 0.1); --card-glass-2: rgba(255, 255, 255, 0.05);
    --card-rim-1: rgba(255, 255, 255, 0.55); --card-rim-2: rgba(255, 255, 255, 0.12);
    --card-rim-3: rgba(255, 255, 255, 0.03); --card-rim-4: rgba(0, 0, 0, 0.5);
    --card-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.22), inset 0 -12px 24px -16px rgba(0, 0, 0, 0.6), 0 26px 48px -18px rgba(0, 0, 0, 0.7), 0 4px 12px -6px rgba(0, 0, 0, 0.5);
    --card-ink-2: rgba(235, 240, 248, 0.95);
    --tab-glass: rgba(30, 34, 42, 0.72); --tab-off: rgba(235, 240, 248, 0.6);
    --fill: rgba(120, 120, 128, 0.36);
    --ink-tint: rgba(244, 246, 248, 0.10); --ink-sel: rgba(244, 246, 248, 0.20);
    --press-bg: #242830; --separator: rgba(255, 255, 255, 0.16);
    --bar-material: rgba(19, 34, 48, 0.94);
    --alert-material: rgba(44, 44, 46, 0.86); --sheet-material: rgba(44, 44, 46, 0.86);
    --sheet-cancel-bg: #2C2C2E; --dim: rgba(0, 0, 0, 0.48);
    --seg-track: rgba(118, 118, 128, 0.24);
    --grabber: rgba(235, 235, 245, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --sky-top: #132230; --sky-mid: #11232A; --sky-low: #0F2222; --sky-bottom: #0B1A17;
  --ink: #F4F6F8; --ink-2: rgba(235, 240, 248, 0.66); --ink-3: rgba(235, 240, 248, 0.34);
  --glass: rgba(255, 255, 255, 0.07); --glass-edge: rgba(255, 255, 255, 0.16); --glass-shade: rgba(0, 0, 0, 0.35);
  --drawer: #1A1D23; --hairline: rgba(255, 255, 255, 0.08);
  --btn-bg: #F4F6F8; --btn-fg: #0A0A0B; --on-red: #FFFFFF; --red-text: #FF6B6F;
  --income: #4CD07A; --red: rgb(255, 66, 69);
  --track: rgba(255, 255, 255, 0.14);
  --glass-sheen: rgba(255, 255, 255, 0.18);
  --orb-1: rgba(110, 185, 255, 0.31); --orb-2: rgba(100, 220, 180, 0.29);
  --orb-3: rgba(90, 205, 215, 0.25); --orb-4: rgba(150, 200, 250, 0.225);
  --card-glass-1: rgba(255, 255, 255, 0.1); --card-glass-2: rgba(255, 255, 255, 0.05);
  --card-rim-1: rgba(255, 255, 255, 0.55); --card-rim-2: rgba(255, 255, 255, 0.12);
  --card-rim-3: rgba(255, 255, 255, 0.03); --card-rim-4: rgba(0, 0, 0, 0.5);
  --card-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.22), inset 0 -12px 24px -16px rgba(0, 0, 0, 0.6), 0 26px 48px -18px rgba(0, 0, 0, 0.7), 0 4px 12px -6px rgba(0, 0, 0, 0.5);
  --card-ink-2: rgba(235, 240, 248, 0.95);
  --tab-glass: rgba(30, 34, 42, 0.72); --tab-off: rgba(235, 240, 248, 0.6);
  --fill: rgba(120, 120, 128, 0.36);
  --ink-tint: rgba(244, 246, 248, 0.10); --ink-sel: rgba(244, 246, 248, 0.20);
  --press-bg: #242830; --separator: rgba(255, 255, 255, 0.16);
  --bar-material: rgba(19, 34, 48, 0.94);
  --alert-material: rgba(44, 44, 46, 0.86); --sheet-material: rgba(44, 44, 46, 0.86);
  --sheet-cancel-bg: #2C2C2E; --dim: rgba(0, 0, 0, 0.48);
  --seg-track: rgba(118, 118, 128, 0.24);
  --grabber: rgba(235, 235, 245, 0.3);
}

/* ---------- 2. 设计 token：字级、间距、尺寸 ----------
   html 用 -apple-system-body，rem = 使用者在 iOS 设定的内文字级（预设 17px），
   其余字级按 HIG 默认比例换算（34/17、20/17 …），跟着 Dynamic Type 一起缩放。 */
:root {
  --font-large-title: 700 2rem/1.206 var(--font-family);        /* 34/41 bold */
  --font-title3: 600 1.1765rem/1.25 var(--font-family);         /* 20/25 */
  --font-headline: 600 1rem/1.294 var(--font-family);           /* 17/22 semibold */
  --font-body: 400 1rem/1.294 var(--font-family);               /* 17/22 */
  --font-subhead: 400 0.8824rem/1.333 var(--font-family);       /* 15/20 */
  --font-footnote: 400 0.7647rem/1.385 var(--font-family);      /* 13/18 */
  --font-caption: 400 0.7059rem/1.333 var(--font-family);       /* 12/16 */
  --font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;

  --radius-card: 12px;
  --hit: 44px;          /* 最小点击区 44x44 pt */
  --tabbar-h: 68px;     /* 胶囊标签栏高度 */
  --tabbar-gap: 12px;   /* 胶囊下方间距 */
  --navbar-h: 44px;
  --margin: 16px;       /* iPhone 版面边距 */

  --tabbar-total: calc(var(--tabbar-h) + var(--tabbar-gap) + var(--safe-bottom));
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);

  --ease-out: cubic-bezier(0.32, 0.72, 0, 1);
}
@media (min-width: 414px) {
  :root { --margin: 20px; }
}

/* ---------- 3. 全域 ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  font-family: var(--font-family);
  font-size: 17px;
  font: -apple-system-body; /* iOS：跟随使用者的字体大小设定（shorthand 会重设 line-height） */
  line-height: 1.294;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-y: none;
}
html.has-layer { overflow: hidden; }

body {
  margin: 0;
  font: -apple-system-body;
  font-family: -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  line-height: 1.294;
  color: var(--ink);
  /* 底色＝天空最顶端的颜色：iOS 26 会取样页面底色给状态栏上色，iOS 18 以前用 theme-color（同色），两者都与天空顶端无缝 */
  background: var(--sky-top);
  overscroll-behavior-y: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

input, textarea, select, [contenteditable] {
  -webkit-user-select: text;
  user-select: text;
  font-size: max(16px, 1rem); /* ≥16px，避免 iOS 自动放大 */
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* 天空背景层：固定、不参与布局与命中，body 第一个子元素 */
.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  contain: strict;
  pointer-events: none;
}
/* 整页「晨雾」：一条连续的线性渐变，从状态栏后面一路到底，没有云、没有色块。
   所有贴顶、满宽的全屏层（.sky、子页面、阻挡画面）共用这一条，顶端都是 sky-top。
   background-color 给 iOS 26 状态栏取样用（它取样底色，不是渐变图）：与 body、theme-color 同色，不能删 */
.sky,
.nav-page,
.overlay.overlay-blocking {   /* 两个 class：要压过后面 .overlay 的 background: var(--dim) */
  background-color: var(--sky-top);
  background-image: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 30%, var(--sky-low) 65%, var(--sky-bottom) 100%);
}
/* 增加对比度 / 降低透明度：各种材质改不透明（结余卡的光球与玻璃在 §15 另外处理） */
@media (prefers-contrast: more), (prefers-reduced-transparency: reduce) {
  :root { --glass: #FFFFFF; --tab-glass: #FFFFFF; --bar-material: #CFE3EF; --alert-material: #F7F7F7; --sheet-material: #F7F7F7; }
  :root[data-theme="dark"] { --glass: #1A1D23; --tab-glass: #1A1D23; --bar-material: #132230; --alert-material: #1A1D23; --sheet-material: #1A1D23; }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark), (prefers-reduced-transparency: reduce) and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --glass: #1A1D23; --tab-glass: #1A1D23; --bar-material: #132230; --alert-material: #1A1D23; --sheet-material: #1A1D23; }
}

h1, h2, p { margin: 0; }

/* 按压回馈 */
.pressable { transition: transform 0.12s ease, opacity 0.12s ease; }
.pressable:active { transform: scale(0.97); opacity: 0.7; }

/* ---------- 4. App 壳与分页 ---------- */
.shell {
  /* 内容不要被 Tab Bar 盖住；首页抽屉用同一个值把自己延伸到画面底部 */
  --shell-pad-bottom: calc(var(--tabbar-total) + 24px);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--shell-pad-bottom);
}
/* 有 toast 时多留出 toast 的高度，最后一行可以滚到 toast 之上 */
body.has-toast .shell { --shell-pad-bottom: calc(var(--tabbar-total) + 24px + 12px + var(--hit) + 16px); }
/* 首页是 flex column：抽屉 flex 撑满剩下的高度（不量测 DOM） */
.screens { flex: 1 0 auto; display: flex; flex-direction: column; }
.screen[data-screen="home"],
.screen[data-screen="home"] > .screen-content,
.screen[data-screen="stats"],
.screen[data-screen="stats"] > .screen-content { flex: 1 0 auto; display: flex; flex-direction: column; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.screen {
  padding-left: calc(var(--margin) + var(--safe-left));
  padding-right: calc(var(--margin) + var(--safe-right));
}

.large-title {
  font: var(--font-large-title);
  letter-spacing: 0.01em;
  padding: 8px 0 8px;   /* 紧贴状态栏下方：安全区域（.shell 的 padding-top）＋ 8px */
  text-align: left;
}
/* 首页：大标题左、当月右 */
.large-title-row {
  display: flex;
  flex-wrap: wrap;               /* 大字级放不下时月份换到下一行，不挤压大标题 */
  align-items: baseline;
  justify-content: space-between;
  column-gap: 12px;
}
.large-title-aside {
  flex: none;
  font: var(--font-subhead);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- 5. Tab Bar ---------- */
.tabbar {
  position: fixed;
  left: calc(max(16px, var(--safe-left)));
  right: calc(max(16px, var(--safe-right)));
  max-width: 520px;   /* iPad / 桌面不拉满 */
  margin-inline: auto;
  bottom: calc(var(--tabbar-gap) + var(--safe-bottom));
  z-index: 50;
  display: grid;
  grid-template-columns: repeat(var(--n, 3), 1fr);
  height: var(--tabbar-h);
  padding: 6px;
  border-radius: 34px;
  background: var(--tab-glass);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid var(--hairline);
  box-shadow: 0 10px 30px -12px var(--glass-shade);
}
/* 黑色胶囊随选中项滑动，带一点回弹 */
.tabbar-pill {
  position: absolute;
  top: 6px; bottom: 6px; left: 6px;
  width: calc((100% - 12px) / var(--n, 3));
  border-radius: 28px;
  background: var(--btn-bg);
  transform: translateX(calc(var(--i, 0) * 100%));
  transition: transform 0.42s cubic-bezier(0.34, 1.45, 0.6, 1);
}

.tabbar-item {
  position: relative;
  z-index: 1;
  min-width: var(--hit);
  display: grid;
  place-items: center;
  align-content: center;
  gap: 3px;
  border-radius: 28px;
  color: var(--tab-off);
  transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}
.tabbar-item svg { stroke-width: 2.3; transition: transform 0.35s cubic-bezier(0.34, 1.6, 0.6, 1); }
.tabbar-item[aria-selected="true"] { color: var(--btn-fg); }
.tabbar-item[aria-selected="true"] svg { transform: scale(1.06); }
.tabbar-item:active svg { transform: scale(0.88); }
.tabbar-item:focus-visible { outline-offset: -4px; }
.tabbar-item[aria-selected="true"]:focus-visible { outline-color: var(--btn-fg); }
@media (prefers-reduced-motion: reduce) {
  .tabbar-pill, .tabbar-item, .tabbar-item svg { transition: none; }
}

.tabbar-label {
  font-size: 11px;      /* Tab Bar 标签固定小字级，不跟 Dynamic Type 放大，避免撑破 */
  font-weight: 600;
  line-height: 11px;
}

/* ---------- 6. 安装提示（顶端） ---------- */
.install-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px calc(var(--margin) + var(--safe-right)) 0 calc(var(--margin) + var(--safe-left));
  padding: 10px 4px 10px 14px;
  border-radius: var(--radius-card);
  /* 玻璃样式但不模糊（backdrop-filter 只留四处） */
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  box-shadow: 0 1px 0 var(--glass-shade);
  font: var(--font-subhead);
  color: var(--label);
  min-width: 0;
}
.install-hint-icon { color: var(--ink); display: flex; flex: none; }
.install-hint-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.install-hint .nowrap { display: inline-block; white-space: normal; } /* 整段优先不拆；过宽时（大字级 / 窄屏）才在段内换行，避免横向滚动 */
.install-hint-close {
  flex: none;
  width: var(--hit);
  height: var(--hit);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--secondary-label);
  font-size: 15px;
  font-weight: 600;
}

/* ---------- 7. 浮层（共用遮罩） ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--dim);
  opacity: 0;
  transition: opacity 0.25s ease;
  overscroll-behavior: contain;
  touch-action: none;
}
.overlay.is-visible { opacity: 1; }

/* ---------- 8. Alert（置中，270pt 宽） ---------- */
.overlay-alert {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
}
.alert {
  width: 270px;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  border-radius: 14px;
  background: var(--alert-material);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  backdrop-filter: saturate(180%) blur(30px);
  text-align: center;
  transform: scale(1.12);
  transition: transform 0.25s var(--ease-out);
  touch-action: auto;
}
.overlay-alert.is-visible .alert { transform: scale(1); }

.alert-body { padding: 19px 16px 20px; }
.alert-title { font: var(--font-headline); }
.alert-message { font: var(--font-footnote); margin-top: 4px; }
.alert-field { /* 点击区 ≥44px，输入框视觉仍为 32px */
  min-height: var(--hit);
  margin-top: 8px;
  display: flex;
  align-items: center;
}
.alert-input {
  display: block;
  width: 100%;
  height: 32px;
  padding: 0 8px;
  border: 0.5px solid var(--separator);
  border-radius: 7px;
  background: var(--bg-grouped-secondary);
  color: var(--label);
  font-family: var(--font-family);
  font-size: 16px;
  text-align: left;
}
.alert-input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }

.alert-buttons {
  display: flex;
  box-shadow: inset 0 0.5px 0 var(--separator);
}
.alert-buttons.is-stacked { flex-direction: column; }
.alert-button {
  flex: 1 1 0;
  min-height: var(--hit);
  padding: 0 8px;
  font: var(--font-body);
  color: var(--ink);
}
.alert-buttons:not(.is-stacked) .alert-button + .alert-button { box-shadow: inset 0.5px 0 0 var(--separator); }
.alert-buttons.is-stacked .alert-button + .alert-button { box-shadow: inset 0 0.5px 0 var(--separator); }
.alert-button.is-bold { font-weight: 600; }
.alert-button.is-destructive { color: var(--red-text); }
.alert-button:disabled { color: var(--tertiary-label); }
.alert-button:active:not(:disabled) { background: var(--fill); }

/* ---------- 9. Action sheet（底部） ---------- */
.overlay-sheet {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) calc(8px + var(--safe-right)) calc(8px + var(--safe-bottom)) calc(8px + var(--safe-left));
}
.action-sheet {
  width: 100%;
  max-width: 420px;
  max-height: 100%; /* 遮罩的 padding 已扣掉安全区 */
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateY(110%);
  transition: transform 0.35s var(--ease-out);
  touch-action: auto;
}
.overlay-sheet.is-visible .action-sheet { transform: translateY(0); }

.sheet-group {
  min-height: 0;
  border-radius: 14px;
  overflow-x: hidden;
  overflow-y: auto; /* 选项太多时只在这一组里滚动 */
  overscroll-behavior: contain;
  background: var(--sheet-material);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  backdrop-filter: saturate(180%) blur(30px);
}
.sheet-head {
  padding: 14px 16px;
  text-align: center;
  color: var(--secondary-label);
}
.sheet-title { font: var(--font-footnote); font-weight: 600; }
.sheet-message { font: var(--font-footnote); margin-top: 2px; }

.sheet-button {
  display: block;
  width: 100%;
  min-height: 57px;
  padding: 8px 16px;
  font: var(--font-body);
  font-size: 1.1765rem; /* action sheet 按钮约 20pt */
  color: var(--ink);
  text-align: center;
}
.sheet-group > * + * { box-shadow: inset 0 0.5px 0 var(--separator); }
.sheet-button.is-destructive { color: var(--red-text); }
.sheet-group .sheet-button:active { background: var(--fill); }
.sheet-cancel {
  flex: none;
  border-radius: 14px;
  background: var(--sheet-cancel-bg);
  font-weight: 600;
}
.sheet-cancel:active { filter: brightness(0.92); }

/* ---------- 10. Toast（Tab Bar 上方） ---------- */
.toast {
  position: fixed;
  z-index: 80; /* 在 Tab Bar(50) 之上、浮层遮罩(100) 之下 */
  left: calc(var(--margin) + var(--safe-left));
  right: calc(var(--margin) + var(--safe-right));
  bottom: calc(var(--tabbar-total) + 12px);
  margin: 0 auto;
  max-width: 420px;
  min-height: var(--hit);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 6px 6px 16px;
  border-radius: 14px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: var(--font-subhead);
  box-shadow: 0 6px 24px var(--glass-shade);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.3s var(--ease-out);
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast-message { flex: 1; padding: 6px 0; font-weight: 400; }
.toast-action {
  flex: none;
  min-height: 36px;
  min-width: var(--hit);
  padding: 0 12px;
  border-radius: 10px;
  color: inherit;
  font-weight: 600;
  position: relative;
}
.toast-action:focus-visible { outline-color: var(--btn-fg); }
.toast-action::after { /* 视觉 36px，点击区扩到 44px */
  content: "";
  position: absolute;
  inset: -4px 0;
}

/* ---------- 10b. 资料库已更新（不可关闭的阻挡画面） ---------- */
/* 阻挡画面：晨雾底（不透明，盖住后面不可操作的内容）+ 黑色胶囊按钮 */
.overlay-blocking { z-index: 300; opacity: 1; }   /* 底色：整页晨雾渐变（与 .sky 共用，见 §3 .sky 规则），不透明 */
.overlay-blocking .alert-buttons { box-shadow: none; padding: 0 16px 16px; }
.overlay-blocking .alert-button { border-radius: 999px; background: var(--btn-bg); color: var(--btn-fg); }
.overlay-blocking .alert-button:active:not(:disabled) { background: var(--btn-bg); opacity: 0.7; }

/* ---------- 11. 开库失败画面 ---------- */
.fatal {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: calc(var(--safe-top) + 24px) calc(32px + var(--safe-right)) calc(var(--safe-bottom) + 24px) calc(32px + var(--safe-left));
  text-align: center;
}
.fatal-title { font: var(--font-title3); }
.fatal-message { font: var(--font-subhead); color: var(--secondary-label); max-width: 320px; overflow-wrap: anywhere; }
.fatal-button {
  margin-top: 12px;
  min-height: 50px;
  min-width: 200px;
  padding: 0 24px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border-radius: 999px;
  font: var(--font-headline);
}

/* ---------- 12. Reduce Motion：取消缩放 / 位移，只留淡入淡出 ---------- */
@media (prefers-reduced-motion: reduce) {
  .pressable:active { transform: none; }
  .alert, .overlay-alert.is-visible .alert,
  .action-sheet, .overlay-sheet.is-visible .action-sheet,
  .toast, .toast.is-visible { transform: none; }
  .pressable, .alert, .action-sheet { transition: none; }
  .toast { transition: opacity 0.2s ease; }
  .overlay { transition: opacity 0.2s ease; }
}

/* =====================================================================
   13. Sheet（底部 modal sheet，large detent）— js/ui/sheet.js
   - [hig-components-dialogs / sheets.md] 可调整的 sheet 要有 grabber、支援下拉关闭；
     取消在左上、完成（储存）在右上。
   - sheet 底色 / 卡片色：走主题 token（--drawer 抽屉色 / --sky-* 天空底），不再用 iOS 分组灰。
   - 分段控件：--seg-track 底，选中块为黑色胶囊（--btn-bg / --btn-fg，深色反相）。
   ===================================================================== */

.overlay-modal {
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  width: 100%;
  max-width: 600px;
  height: calc(100% - var(--safe-top) - 10px);
  display: flex;
  flex-direction: column;
  border-radius: 30px 30px 0 0;
  background: var(--drawer);
  box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.12);
  transform: translateY(100%);
  transition: transform 0.4s var(--ease-out);
  touch-action: auto;
  overflow: hidden;
}
.overlay-modal.is-visible .modal-sheet { transform: translateY(0); } /* 下拉中由 inline transform 覆盖 */
.modal-sheet.is-dragging { transition: none; }

/* 把手 + 标题列：可下拉的区域 */
.modal-sheet-header {
  flex: none;
  touch-action: none;
  cursor: grab;
  padding: 5px calc(var(--safe-right)) 0 calc(var(--safe-left));
}
.modal-sheet-grabber {
  width: 36px;
  height: 5px;
  margin: 0 auto;
  border-radius: 2.5px;
  background: var(--grabber);
}
.modal-sheet-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: var(--navbar-h);
}
.modal-sheet-title { font: var(--font-headline); text-align: center; padding: 0 4px; }
.modal-sheet-left { justify-self: start; }
.modal-sheet-right { justify-self: end; }
.modal-sheet-action {
  min-height: var(--hit);
  min-width: var(--hit);
  padding: 0 var(--margin);
  font: var(--font-body);
  color: var(--ink);
  touch-action: manipulation;
}
.modal-sheet-action.is-bold { font-weight: 600; }
.modal-sheet-action:disabled { color: var(--ink-3); }
.modal-sheet-action:active:not(:disabled) { opacity: 0.5; }

.modal-sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* --keyboard：键盘高度（sheet.js 依 visualViewport 设定），储存按钮与输入框不被遮住 */
  padding: 8px calc(var(--margin) + var(--safe-right)) calc(var(--safe-bottom) + 24px + var(--keyboard, 0px)) calc(var(--margin) + var(--safe-left));
}

/* =====================================================================
   14. Entry sheet（记一笔 / 编辑）— js/ui/entry-sheet.js
   - [hig-components-controls] 分段控件：2 个互斥、等宽、名词标签；文本框用对应键盘
     （inputmode=decimal）、给提示文字、适时验证。输入框字级 ≥16px（金额约 2.6rem，上限 64px）。
   ===================================================================== */
.entry { display: flex; flex-direction: column; gap: 20px; padding-top: 4px; }

/* 支出 / 收入 分段控件：黑色胶囊（与标签栏同语言），共用于统计页、记一笔、分类管理。
   轨道 = 玻璃 + 玻璃边；选中 = --btn-bg / --btn-fg 的胶囊底块（transform 滑动，只走合成）。高 44pt。 */
.segmented {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: var(--hit);
  margin: 6px 0;
  padding: 3px;
  border-radius: 22px;
  background: var(--glass);
  border: 1px solid var(--glass-edge);
}
.segmented::before { /* 选中的胶囊底块 */
  content: "";
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: 19px;
  background: var(--btn-bg);
  transition: transform 0.25s var(--ease-out);
}
.segmented[data-selected="income"]::before { transform: translateX(100%); }
.segment {
  position: relative;
  z-index: 1;
  min-height: 36px;
  border-radius: 19px;
  font: var(--font-subhead);
  font-weight: 600;
  color: var(--ink);
  transition: color 0.2s ease;
}
.segment[aria-checked="true"] { color: var(--btn-fg); }
/* 抽屉是白底：轨道改用 ink 淡色，去掉玻璃边（深色时 ink-tint 同样可见） */
.modal-sheet .segmented { background: var(--ink-tint); border-color: transparent; }
.segment::after { content: ""; position: absolute; inset: -4px 0; } /* 36pt 按钮的点击区扩到 44pt */
.segment:focus-visible { outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .segment { transition: none; }
}

/* 金额：大字、前面固定 RM */
.entry-amount-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 68px;
  padding: 12px 16px;
  border-radius: var(--radius-card);
  background: var(--ink-tint); /* 抽屉是白底：分组卡改用 ink 淡色 */
  cursor: text;
}
.entry-amount-prefix { font: var(--font-title3); color: var(--secondary-label); }
.entry-amount-input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  caret-color: var(--ink);
  font-family: var(--font-family);
  font-size: min(calc(1rem * 2.6), 64px);
  font-weight: 300;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.entry-amount-input::placeholder { color: var(--tertiary-label); }
.entry-amount-input::selection { background: var(--ink-sel); color: var(--ink); }
.entry-amount.has-error .entry-amount-row { box-shadow: inset 0 0 0 1px var(--red); }

/* 区段标题与卡片 */
.entry-section-label {
  margin: 0;
  padding: 0 16px 6px;
  font: var(--font-footnote);
  color: var(--secondary-label);
}
.entry-card { border-radius: var(--radius-card); background: var(--ink-tint); }
.entry-card.cat-card { background: transparent; } /* 分类格直接放在抽屉上，选中环的间隙才与底色一致 */

/* 分类网格：每列 4 个，每格 ≥ 44x44 */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 4px;
  padding: 12px 6px;
}
.cat-tile {
  position: relative;
  min-width: var(--hit);
  min-height: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 4px 2px;
  border-radius: 12px;
}
.cat-tile-icon {
  width: 44px;
  height: 44px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink);
  background: var(--ink-tint);
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.cat-tile-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: var(--font-caption);
  color: var(--ink-2);
}
/* 选中：圆标外一圈 2px ink 外框，中间留 2px 抽屉色间隙（彩色圆标上才看得清）。
   注意：间隙色假设图格放在 --drawer 上（记一笔面板的分类格就是）；换底色要同步改。 */
.cat-tile[aria-pressed="true"] .cat-tile-icon { box-shadow: 0 0 0 2px var(--drawer), 0 0 0 4px var(--ink); }
.cat-tile[aria-pressed="true"] .cat-tile-name { color: var(--ink); font-weight: 600; }
.cat-tile:active .cat-tile-icon { filter: brightness(0.92); }
.cat-tile:focus-visible { outline-offset: 0; }
.cat-tile-badge {
  margin-top: -4px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--fill);
  color: var(--secondary-label);
  font-size: 11px;
  line-height: 15px;
}
.cat-tile.is-deleted .cat-tile-icon, .cat-tile-add .cat-tile-icon { color: var(--ink-2); background: var(--fill); }
.cat-tile-plus { font-size: 22px; line-height: 1; }

/* 日期、备注：inset grouped 列表 */
.entry-row {
  position: relative;
  min-height: var(--hit);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
}
.entry-row + .entry-row::before { /* 内缩分隔线 */
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}
.entry-row-label { font: var(--font-body); }
.entry-input {
  margin: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--label);
  font-family: var(--font-family);
  font-size: max(16px, 1rem);
}
.entry-input[type="date"] {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--seg-track);
  text-align: right;
}
.entry-input[type="date"]:focus-visible { outline: 2px solid var(--ink); outline-offset: 0; }
.entry-note { flex: 1; min-width: 0; padding: 11px 0; }
.entry-note::placeholder { color: var(--tertiary-label); }

.entry-delete {
  width: 100%;
  min-height: var(--hit);
  border-radius: var(--radius-card);
  background: transparent;           /* 红字放在 ink-tint 上对比不足：改透明底 + 发丝边 + 深一档的红字 */
  border: 1px solid var(--separator);
  color: var(--red-text);
  font: var(--font-body);
}
.entry-delete:active { filter: brightness(0.92); }

/* 验证错误：红字 + 抖动 */
.field-error {
  padding: 6px 16px 0;
  font: var(--font-footnote);
  color: var(--red-text);
}
.is-shaking { animation: entry-shake 0.4s ease; }
@keyframes entry-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

/* Reduce Motion：sheet 不滑动（只有遮罩淡入），不抖动 */
@media (prefers-reduced-motion: reduce) {
  .modal-sheet { transition: none; }
  .overlay-modal:not(.is-visible) .modal-sheet { transform: none; }
  .segmented::before, .cat-tile-icon { transition: none; }
  .is-shaking { animation: none; }
}

/* =====================================================================
   15. Home（首页）— js/ui/home.js
   - [hig-components-content] 空状态要告诉使用者怎么开始；大量资料分页（200 笔 + 显示更多）。
   - [hig-patterns] 删除不跳确认框，改用「撤销」toast；左滑露出红色「删除」（80pt）。
   - 列表是 inset grouped：12pt 圆角卡片、内缩分隔线、组标题用 footnote 次要色。
   ===================================================================== */
/* ---------- 结余卡「晨雾」：光球在卡片后面，卡片是半透明玻璃（无 backdrop-filter） ----------
   效能：光球与玻璃全是静态渐变和阴影，没有模糊、没有动画，只在重绘时算一次。
   层叠：首页 .screen 自成层叠上下文；光球是包装层的 ::before（z-index:-1），
   所以在大标题、卡片、「记一笔」按钮、抽屉下面，在 .sky 上面。包装层自己不能建层叠上下文。 */
.screen[data-screen="home"] { isolation: isolate; }
.home-card-wrap { position: relative; margin-top: 10px; }
.home-card-wrap::before {
  /* 光球层：左右伸到屏幕边（不超出，避免横向滚动），上方只伸出 56px（不碰状态栏），高度固定。
     光球位置：横向＝卡片宽度的比例，纵向＝离卡片顶端的固定 px（卡片变高也不会往上漂）。
     每个光球在 70% 半径处已完全透明；纵向都在图层内淡完（测试会检查），横向超出的部分被屏幕边切掉，看不出来。
     left / right 必须等于 .screen 的左右 padding（测试会检查），否则会横向滚动。 */
  --mx: calc(var(--margin) + var(--safe-left));
  content: "";
  position: absolute;
  z-index: -1;
  pointer-events: none;
  top: -56px;
  height: 390px;
  left: calc(-1 * var(--mx));
  right: calc(-1 * (var(--margin) + var(--safe-right)));
  background:
    radial-gradient(240px 170px at calc(var(--mx) + (100% - 2 * var(--mx)) * 0.874) 119px, var(--orb-1), transparent 70%),
    radial-gradient(260px 200px at calc(var(--mx) + (100% - 2 * var(--mx)) * 0.18) 234px, var(--orb-2), transparent 70%),
    radial-gradient(200px 170px at calc(var(--mx) + (100% - 2 * var(--mx)) * 1.036) 267px, var(--orb-3), transparent 70%),
    radial-gradient(220px 170px at calc(var(--mx) + (100% - 2 * var(--mx)) * 0.126) 151px, var(--orb-4), transparent 70%);
}
.home-card {
  position: relative;
  isolation: isolate;
  padding: 22px 22px 20px;
  border-radius: 30px;
  background: linear-gradient(155deg, var(--card-glass-1), var(--card-glass-2));
  box-shadow: var(--card-shadow);   /* 上缘内亮线、下缘内阴影（玻璃厚度）＋两层投影（浮起来） */
}
/* 渐层反光边：1.3px 的框，左上亮 → 右下暗；用 mask 挖空中间 */
@supports (mask-composite: exclude) or (-webkit-mask-composite: xor) {
  .home-card::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 0;
    padding: 1.3px;
    border-radius: inherit;
    pointer-events: none;
    background: linear-gradient(140deg, var(--card-rim-1), var(--card-rim-2) 35%, var(--card-rim-3) 60%, var(--card-rim-4));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask: linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0);
  }
}
@supports not ((mask-composite: exclude) or (-webkit-mask-composite: xor)) {
  .home-card { border: 1px solid var(--card-rim-2); }   /* 不支援 mask 时：普通细边 */
}
.home-card > * { position: relative; z-index: 1; }
/* 眼睛按钮：右上角 44×44 点击区（.home-card > .home-eye 优先级高于 .home-card > *，position 不会被盖掉） */
.home-card > .home-eye {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 22px;
  color: var(--card-ink-2);   /* 次要控件：比金额轻一级（非文字 ≥3:1） */
}
.home-card-label { padding-right: 36px; font: var(--font-subhead); color: var(--card-ink-2); }
.home-balance {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;               /* 极端长度 / 大字级时宁可换行也不溢出 */
  align-items: baseline;
  column-gap: 8px;
  font-variant-numeric: tabular-nums;
}
/* 金额加粗、加深：在玻璃上要清楚。字级用 rem＋上限：一般结余可随大字放大到 64px；
   is-long（≥RM 10,000）与窄屏的上限等于预设大小，只会缩小、不会放大——为了长数字一定放得下一行（实测过 320/375/430 × 字级 17–23）。
   上限不要随手调大，改了要重新实测 */
.home-balance-cur { font: 700 min(1.1765rem, 22px)/1 var(--font-family); color: var(--ink); }   /* 20；上限让大字级时长数字仍放得下一行 */
.home-balance-sign { font: 700 min(1.1765rem, 22px)/1 var(--font-family); color: var(--ink); margin-right: -6px; }
.home-balance-int {
  font: 750 min(calc(1rem * 2.94), 64px)/1.05 var(--font-family);                    /* ≈50 */
  letter-spacing: -0.03em;
  white-space: nowrap;
}
.home-balance-dec {
  margin-left: -6px;
  font: 700 min(calc(1rem * 1.41), 30px)/1 var(--font-family);                       /* ≈24 */
  color: var(--ink);
}
/* 粗体比细体宽：长数字缩级比旧版多缩一点 */
.home-balance.is-long .home-balance-int { font-size: min(calc(1rem * 2.35), 40px); }  /* ≈40；上限 40：375 宽大字级时 9 字元仍一行 */
.home-balance.is-long .home-balance-dec { font-size: min(calc(1rem * 1.18), 22px); }  /* ≈20 */
.home-balance.is-xlong .home-balance-int { font-size: min(calc(1rem * 1.88), 36px); } /* ≈32 */
.home-balance.is-xlong .home-balance-dec { font-size: min(calc(1rem * 1.06), 22px); } /* ≈18 */
/* 窄屏（iPhone SE 320 宽，卡片内容约 244px）：长数字再缩一级，小数才不会单独掉到下一行。
   上限贴近预设字级的大小：320 宽的人常开大字，上限放松一点就又会掉行（「RM」、负号也一起设上限）。
   必须写在上面同优先级的规则之后（靠文件顺序压过，测试会检查） */
@media (max-width: 359px) {
  .home-balance-cur,
  .home-balance-sign { font-size: min(1.1765rem, 21px); }
  .home-balance-int { font-size: min(calc(1rem * 2.94), 50px); }                       /* ≈50 */
  .home-balance-dec { font-size: min(calc(1rem * 1.41), 24px); }                       /* ≈24 */
  .home-balance.is-long .home-balance-int { font-size: min(calc(1rem * 2), 34px); }     /* ≈34：9 字元整行约 236px */
  .home-balance.is-long .home-balance-dec { font-size: min(calc(1rem * 1.12), 19px); }  /* ≈19 */
  .home-balance.is-xlong .home-balance-int { font-size: min(calc(1rem * 1.65), 29px); } /* ≈28 */
  .home-balance.is-xlong .home-balance-dec { font-size: min(calc(1rem * 0.94), 17px); } /* ≈16 */
}

.home-flow {
  display: flex;
  flex-wrap: wrap;               /* 两栏放不下（金额不断行）时，支出换到下一行 */
  gap: 12px;
  margin-top: 20px;
}
.home-flow-item { flex: 1 1 calc(50% - 6px); display: grid; align-content: start; gap: 2px; }
.home-flow-k {
  display: flex;
  align-items: center;
  gap: 4px;
  font: var(--font-footnote);
  color: var(--card-ink-2);
}
.home-flow-k svg { flex: none; }
.home-flow-v {
  font: var(--font-body);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;           /* 「RM」与数字不断开 */
}
.home-flow-v.is-small { font-size: 0.8824rem; }   /* 缩一级（subhead 字级） */
/* 窄屏：粗体金额较宽，一般金额（到 RM 999,999.99）也缩一级，收入、支出才能并排；百万以上会上下堆叠（flex-wrap） */
@media (max-width: 359px) {
  .home-flow-v { font-size: 0.8824rem; }
}

/* 比例线：线宽 = 支出占收入的百分比；超过收入 → 满格、同色 */
.home-meter { display: grid; gap: 7px; margin-top: 16px; }
.home-meter-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--track);
  overflow: hidden;
}
.home-meter-fill {
  display: block;
  height: 100%;
  border-radius: 2px;
  background: var(--ink);
}
.home-meter-note {
  font: var(--font-caption);
  color: var(--card-ink-2);
  font-variant-numeric: tabular-nums;
}

/* 增加对比度 / 降低透明度：拿掉光球与渐层反光边，卡片改成不透明＋实线边
   （放在结余卡规则之后，才压得过上面的 background） */
@media (prefers-contrast: more), (prefers-reduced-transparency: reduce) {
  .home-card-wrap::before,
  .home-card::before { display: none; }
  .home-card { background: var(--glass); border: 1px solid var(--glass-edge); }
}
@media (prefers-contrast: more) {
  .home-card { border-color: var(--ink-2); }
}

/* ---------- 主按钮：黑色胶囊 ---------- */
.home-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 54px;
  margin-top: 16px;
  border-radius: 27px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: var(--font-headline);
}
.home-add:focus-visible { outline-offset: 3px; }

/* ---------- 账单抽屉：满版宽、上圆角，最少撑到画面底部 ---------- */
.home-drawer,
.stats-drawer {
  position: relative;
  flex: 1 0 auto;
  margin: 22px calc(-1 * (var(--margin) + var(--safe-right))) calc(-1 * var(--shell-pad-bottom))
    calc(-1 * (var(--margin) + var(--safe-left)));
  padding: 18px 0 var(--shell-pad-bottom);
  border-radius: 30px 30px 0 0;
  background: var(--drawer);
}
.home-drawer::before,
.stats-drawer::before { /* 阴影只挂在顶端 30px，不挂在可能很长的抽屉本身 */
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 30px;
  border-radius: 30px 30px 0 0;
  box-shadow: 0 -10px 30px -18px var(--glass-shade);
  pointer-events: none;
}
.home-drawer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px calc(20px + var(--safe-right)) 6px calc(20px + var(--safe-left));
}
.home-drawer-title { font: var(--font-title3); }
.home-drawer-count {
  font: var(--font-footnote);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.home-empty {
  padding: 48px 16px;
  text-align: center;
  font: var(--font-subhead);
  color: var(--secondary-label);
}

/* 日期组 */
.home-day-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px calc(20px + var(--safe-right)) 4px calc(20px + var(--safe-left));
  font: var(--font-footnote);
  color: var(--ink-2);
}
.home-day-net { font-variant-numeric: tabular-nums; white-space: nowrap; }
.home-group {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--drawer);
  isolation: isolate;
}

/* 一列：红色删除按钮在下层（右侧），内容在上层可左右滑动。列与子元素不加阴影 / 渐层（滚动效能） */
.home-row {
  position: relative;
  overflow: hidden;
}
.home-row-content {
  position: relative;
  z-index: 1;
  width: 100%;
  min-height: 62px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px calc(20px + var(--safe-right)) 9px calc(20px + var(--safe-left));
  text-align: left;
  background: var(--drawer);
  touch-action: pan-y;           /* 垂直滚动交给浏览器，水平给左滑 */
  -webkit-touch-callout: none;
}
.home-row-content:active { background: var(--press-bg); }
.home-row-content:focus-visible { outline-offset: -2px; }
.home-row-icon {
  flex: none;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--ink);
  background: var(--ink-tint);
}
.home-row .home-row-icon { width: 44px; height: 44px; }
.home-row-icon.is-muted { color: var(--secondary-label); background: var(--fill); }
.home-row-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.home-row-name, .home-row-note {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.home-row-name { font: var(--font-body); font-weight: 500; }
.home-row-note { font: var(--font-footnote); color: var(--ink-2); }
.home-row-amount {
  flex: none;
  font: var(--font-body);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--ink);
}
.home-row-amount.is-income { color: var(--income); }

.home-row-delete {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80px;
  background: var(--red);
  color: var(--on-red);
  font: var(--font-body);
  opacity: 0;                  /* 未滑开时透明（避免边缘透出红色）；仍可被键盘 / VoiceOver 聚焦 */
}
.home-row.is-revealed .home-row-delete,
.home-row-delete:focus { opacity: 1; }
/* 没滑开时不接受点按（键盘 / VoiceOver 仍可到达；聚焦时列会滑开） */
.home-row:not(.is-revealed) .home-row-delete { pointer-events: none; }
.home-row-delete:focus-visible { outline: 2px solid var(--on-red); outline-offset: -4px; }
.home-row-content.is-animating { transition: transform 0.3s var(--ease-out); }
.home-row-delete.is-animating { transition: width 0.3s var(--ease-out); }

.home-more {
  display: block;
  width: calc(100% - 40px - var(--safe-left) - var(--safe-right));
  min-height: var(--hit);
  margin: 12px calc(20px + var(--safe-right)) 0 calc(20px + var(--safe-left));
  border-radius: 22px;
  background: var(--ink-tint);
  color: var(--ink);
  font: var(--font-body);
}
.home-more:active { background: var(--ink-sel); }

/* Reduce Motion：左滑放开后直接定位，不做弹回动画 */
@media (prefers-reduced-motion: reduce) {
  .home-row-content.is-animating, .home-row-delete.is-animating { transition: none; }
}

/* =====================================================================
   15. Stats 统计页 — js/ui/stats-view.js、js/ui/trend-chart.js
   - 顺序：月份切换 → 摘要玻璃卡（无光晕）→ 黑色胶囊分段 → 累计走势图卡 → 分类抽屉。
   - [dataviz] 走势图单色 ink；比例条用分类色，但每列都有名称 + 金额 + 百分比文字，条本身 aria-hidden。
   - 效能：玻璃卡是静态渐层（无 backdrop-filter）；分类列不加阴影 / 渐层；拖动只改标记与标签属性。
   ===================================================================== */
.stats-month {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.stats-month-title { font: var(--font-headline); text-align: center; flex: 1; font-variant-numeric: tabular-nums; }
.stats-month-btn {
  width: var(--hit);
  height: var(--hit);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 22px;
  color: var(--ink);
}
.stats-month-btn[aria-disabled="true"] { color: var(--ink-3); }

/* 共用玻璃卡（无光晕）：静态渐层 + 玻璃边，不用 backdrop-filter */
.glass-card {
  border-radius: 26px;
  background: linear-gradient(155deg, var(--glass-sheen), transparent 45%), var(--glass);
  border: 1px solid var(--glass-edge);
  box-shadow: inset 0 1px 0 var(--glass-edge), 0 18px 40px -18px var(--glass-shade);
}

/* 摘要：三栏；金额放不下时自动换行（不截断） */
.stats-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 8px;
  padding: 16px 18px;
}
.stats-sum-item { flex: 1 1 0; min-width: max-content; display: grid; gap: 4px; }
.stats-sum-k { font: var(--font-footnote); color: var(--ink-2); }
.stats-sum-v {
  font: 500 0.9412rem/1.2 var(--font-family);   /* 16/17 */
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stats-sum-v.is-income { color: var(--income); }

.stats-summary + .segmented { margin: 16px 0 0; }

/* 走势图卡 */
.trend-card { margin-top: 12px; padding: 16px 14px 12px; }
.trend-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  padding: 0 4px 6px;
}
.trend-title { font: var(--font-subhead); font-weight: 600; }
.trend-total {
  font: var(--font-footnote);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.trend-box { position: relative; }
.trend-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
  touch-action: pan-y;           /* 上下滑交给页面滚动，水平拖动给图表 */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: crosshair;
}
.trend-svg:focus-visible { outline: 2px solid var(--ink); outline-offset: 4px; border-radius: 8px; }
.trend-base { stroke: var(--hairline); stroke-width: 1; }
.trend-future { stroke: var(--ink-3); stroke-width: 1; stroke-dasharray: 2 4; }
.trend-line {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.trend-area { stroke: none; }
.trend-stop0 { stop-color: var(--ink); stop-opacity: 0.12; }
.trend-stop1 { stop-color: var(--ink); stop-opacity: 0; }
.trend-single { fill: var(--ink); }
.trend-mline { stroke: var(--ink-3); stroke-width: 1; }
.trend-mdot { fill: var(--btn-bg); stroke: var(--drawer); stroke-width: 2.5; }
.trend-tip {
  position: absolute;
  top: 0;
  left: 0;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font: var(--font-caption);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
.trend-axis {
  position: relative;
  height: calc(0.6471rem * 1.333 + 6px);   /* 11/17 字级的一行 + 上方间距 */
  margin-top: 6px;
  font: 400 0.6471rem/1.333 var(--font-family);   /* 11/17 */
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.trend-tick { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.trend-tick:first-child { transform: none; }          /* 「1 日」靠左对齐，不超出卡片 */
.trend-tick:last-child { transform: translateX(-100%); }
.trend-empty {
  padding: 40px 8px 44px;
  text-align: center;
  font: var(--font-subhead);
  color: var(--ink-2);
}

/* 分类抽屉（与首页账单抽屉同样式，见上方 .home-drawer） */
.stats-drawer { margin-top: 18px; }
.stats-group { list-style: none; margin: 0; padding: 6px 0 0; }
.stats-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 9px calc(20px + var(--safe-right)) 9px calc(20px + var(--safe-left));
}
.stats-row .home-row-icon { width: 44px; height: 44px; }
.stats-row-text { flex: 1; min-width: 0; display: grid; gap: 7px; }
.stats-row-name {
  font: var(--font-body);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stats-bar {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: var(--track);
  overflow: hidden;
}
.stats-bar-fill { display: block; height: 100%; border-radius: 3px; background: var(--cat-fg, var(--secondary-label)); }
.stats-row-nums { flex: none; display: grid; justify-items: end; gap: 3px; }
.stats-row-amount {
  font: var(--font-body);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.stats-row-pct {
  font: var(--font-caption);
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* =====================================================================
   16. Settings 设置页 — js/ui/settings.js
   - [hig-patterns / settings.md] App 内设定只放常用项目；分组 + 简短说明。
   - [hig-components-layout / lists-and-tables.md] inset grouped：组标题 footnote 次要色、
     12pt 圆角卡片、内缩分隔线；推入子画面的列尾有 chevron，动作列用 ink 字、不加 chevron。
   ===================================================================== */
.settings-section { margin-top: 24px; }
.settings-section:first-child { margin-top: 4px; }
.settings-header {
  padding: 0 16px 6px;
  font: var(--font-footnote);
  color: var(--secondary-label);
}
.settings-footer {
  padding: 6px 16px 0;
  font: var(--font-footnote);
  color: var(--secondary-label);
}

/* 共用：inset grouped 卡片与列（设置页、分类子画面） */
.inset-group {
  list-style: none;
  margin: 0;
  padding: 0;
  border-radius: var(--radius-card);
  background: var(--bg-grouped-secondary);
  overflow: hidden;
  isolation: isolate;
}
.inset-row {
  position: relative;
  width: 100%;
  min-height: var(--hit);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  text-align: left;
  font: var(--font-body);
  color: var(--label);
  background: var(--bg-grouped-secondary);
}
.inset-row + .inset-row::before { /* 内缩分隔线 */
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  height: 0.5px;
  background: var(--hairline);
}
button.inset-row:active { background: var(--press-bg); }
.inset-row:focus-visible { outline-offset: -2px; }
.inset-row.is-action { color: var(--ink); }
.inset-row-label { flex: 1; min-width: 0; }
.inset-row-detail { flex: none; color: var(--secondary-label); font-variant-numeric: tabular-nums; }
.inset-row-chevron { flex: none; display: flex; color: var(--ink-3); }

/* =====================================================================
   17. Categories page 分类管理子画面 — js/ui/categories-page.js
   - [hig-components-layout] 导航推入：从右边滑入，左上返回键（chevron + 上一页标题），标题置中。
   - [hig-patterns / feedback] 删除前用 action sheet 确认（破坏性按钮红字）。
   - 列：36pt 图示圆圈（沿用 .home-row-icon）+ 名称 + chevron；分隔线内缩到文字起点。
   ===================================================================== */
.nav-page {
  position: fixed;
  inset: 0;
  z-index: 100;               /* 与其他浮层同层，后开的在上面（DOM 顺序） */
  display: flex;
  flex-direction: column;
  /* 底色：整页晨雾渐变，顶端 sky-top（与状态栏、导航条同色；iOS 26 会取样这个固定层的 background-color）。
     规则与 .sky 共用（§3 .sky 规则），这里不再另写 */
  box-shadow: -2px 0 20px rgba(0, 0, 0, 0.12);
  transform: translateX(100%);
  transition: transform 0.35s var(--ease-out);
}
.nav-page.is-visible { transform: translateX(0); }
.nav-page-bar {
  flex: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: calc(var(--navbar-h) + var(--safe-top));
  padding: var(--safe-top) var(--safe-right) 0 var(--safe-left);
  background: var(--bar-material);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: inset 0 -0.5px 0 var(--separator);
}
.nav-back {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  min-height: var(--hit);
  min-width: var(--hit);
  padding: 0 12px 0 6px;
  color: var(--ink);
  font: var(--font-body);
}
.nav-back-chevron { display: flex; }
.nav-back:active { opacity: 0.5; }
.nav-page-title { font: var(--font-headline); text-align: center; padding: 0 4px; }
.nav-page-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 10px calc(var(--margin) + var(--safe-right)) calc(var(--safe-bottom) + 24px) calc(var(--margin) + var(--safe-left));
}
.nav-page-body .segmented { margin-bottom: 18px; }

.cat-row { position: relative; overflow: hidden; }
.cat-row-main {
  position: relative;
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 16px;
  text-align: left;
  background: var(--bg-grouped-secondary);
}
.cat-row-main:active { background: var(--press-bg); }
.cat-row-main:focus-visible { outline-offset: -2px; }
.cat-row + .cat-row .cat-row-main::before { /* 内缩分隔线：从文字起点开始 */
  content: "";
  position: absolute;
  top: 0;
  left: 64px;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}
.cat-row-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font: var(--font-body);
}
.cat-row-chevron { flex: none; display: flex; color: var(--tertiary-label); }
.cat-row-add .cat-row-main { color: var(--ink); }
.cat-row-plus {
  flex: none;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* 列尾「删除」：平常看不见也点不到；键盘 Tab / VoiceOver 聚焦时显示在列右侧 */
.cat-row-delete {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 80px;
  background: var(--red);
  color: var(--on-red);
  font: var(--font-body);
  opacity: 0;
  pointer-events: none;
}
.cat-row-delete:focus { opacity: 1; pointer-events: auto; z-index: 1; }
.cat-row-delete:focus-visible { outline: 2px solid var(--on-red); outline-offset: -4px; }

/* 新增 / 编辑分类 sheet：名称列 + 图示网格（只有图示，没有文字） */
.cat-name-input { flex: 1; min-width: 0; padding: 11px 0; }
.cat-name-input::placeholder { color: var(--tertiary-label); }
.icon-grid .cat-tile { min-height: 60px; justify-content: center; }

@media (prefers-reduced-motion: reduce) {
  .nav-page { transform: none; opacity: 0; transition: opacity 0.2s ease; }
  .nav-page.is-visible { transform: none; opacity: 1; }
}

/* 设置页「有新版本 · 更新」：行高保持 44pt，点击区用 ::after 扩大 */
button.update-action {
  appearance: none; border: 0; font: inherit;
  background: var(--btn-bg); color: var(--btn-fg); font-weight: 600; font-size: 0.8824rem;
  cursor: pointer; padding: 4px 12px; margin: 0; position: relative; border-radius: 999px;
}
button.update-action::after { content: ""; position: absolute; inset: -12px -8px; }

/* ===== 分类颜色（Task 2）：[data-icon] 设定 --cat-bg / --cat-fg，任何元件都可套用 ===== */
[data-icon="food"] { --cat-bg: #FFE4CF; --cat-fg: #C85A08; }
[data-icon="transport"] { --cat-bg: #D8E8FF; --cat-fg: #1D63BF; }
[data-icon="shopping"] { --cat-bg: #FFDCE8; --cat-fg: #B92E62; }
[data-icon="bills"] { --cat-bg: #D3F0EA; --cat-fg: #137767; }
[data-icon="fun"] { --cat-bg: #E8DFFF; --cat-fg: #6040C4; }
[data-icon="other"] { --cat-bg: #E6E8EC; --cat-fg: #4A5160; }
[data-icon="salary"] { --cat-bg: #D8F2DC; --cat-fg: #1F7D36; }
[data-icon="bonus"] { --cat-bg: #FFF0BF; --cat-fg: #9A6B00; }
[data-icon="side"] { --cat-bg: #DDE1FF; --cat-fg: #3E4CBF; }
[data-icon="other_income"] { --cat-bg: #DCEBE6; --cat-fg: #2D6B57; }
[data-icon="pet"] { --cat-bg: #F3DCF6; --cat-fg: #8A3FB0; }
[data-icon="health"] { --cat-bg: #FFDAD8; --cat-fg: #C0262D; }
[data-icon="home"] { --cat-bg: #EFE6D2; --cat-fg: #7A5B12; }
[data-icon="gift"] { --cat-bg: #F9D9F2; --cat-fg: #A4289A; }
[data-icon="travel"] { --cat-bg: #D0EDF8; --cat-fg: #0E6F94; }
[data-icon="education"] { --cat-bg: #E3F0C4; --cat-fg: #52700E; }
[data-icon="coffee"] { --cat-bg: #EBDCCF; --cat-fg: #7A4A2A; }
[data-icon="phone"] { --cat-bg: #DDF1D0; --cat-fg: #2F7A1C; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) [data-icon="food"] { --cat-bg: rgba(255, 140, 50, 0.18); --cat-fg: #FFA35C; }
  :root:not([data-theme="light"]) [data-icon="transport"] { --cat-bg: rgba(70, 150, 255, 0.18); --cat-fg: #7DB4FF; }
  :root:not([data-theme="light"]) [data-icon="shopping"] { --cat-bg: rgba(255, 90, 150, 0.18); --cat-fg: #FF8DB6; }
  :root:not([data-theme="light"]) [data-icon="bills"] { --cat-bg: rgba(40, 200, 170, 0.18); --cat-fg: #5FD9C0; }
  :root:not([data-theme="light"]) [data-icon="fun"] { --cat-bg: rgba(150, 110, 255, 0.2); --cat-fg: #B49BFF; }
  :root:not([data-theme="light"]) [data-icon="other"] { --cat-bg: rgba(134, 143, 162, 0.19); --cat-fg: #AEB4C1; }
  :root:not([data-theme="light"]) [data-icon="salary"] { --cat-bg: rgba(60, 200, 100, 0.18); --cat-fg: #6EDB8C; }
  :root:not([data-theme="light"]) [data-icon="bonus"] { --cat-bg: rgba(255, 200, 40, 0.18); --cat-fg: #FFD25C; }
  :root:not([data-theme="light"]) [data-icon="side"] { --cat-bg: rgba(110, 125, 255, 0.2); --cat-fg: #9FA9FF; }
  :root:not([data-theme="light"]) [data-icon="other_income"] { --cat-bg: rgba(120, 160, 140, 0.19); --cat-fg: #A3C2B2; }
  :root:not([data-theme="light"]) [data-icon="pet"] { --cat-bg: rgba(170, 81, 215, 0.19); --cat-fg: #C68BE4; }
  :root:not([data-theme="light"]) [data-icon="health"] { --cat-bg: rgba(236, 60, 68, 0.19); --cat-fg: #F27D82; }
  :root:not([data-theme="light"]) [data-icon="home"] { --cat-bg: rgba(160, 145, 90, 0.19); --cat-fg: #CDBE8E; }
  :root:not([data-theme="light"]) [data-icon="gift"] { --cat-bg: rgba(229, 67, 216, 0.19); --cat-fg: #EE81E5; }
  :root:not([data-theme="light"]) [data-icon="travel"] { --cat-bg: rgba(43, 195, 253, 0.19); --cat-fg: #72D7FD; }
  :root:not([data-theme="light"]) [data-icon="education"] { --cat-bg: rgba(186, 247, 49, 0.19); --cat-fg: #D1FA75; }
  :root:not([data-theme="light"]) [data-icon="coffee"] { --cat-bg: rgba(150, 110, 85, 0.19); --cat-fg: #C4A28C; }
  :root:not([data-theme="light"]) [data-icon="phone"] { --cat-bg: rgba(98, 231, 65, 0.19); --cat-fg: #97EF80; }
}
:root[data-theme="dark"] [data-icon="food"] { --cat-bg: rgba(255, 140, 50, 0.18); --cat-fg: #FFA35C; }
:root[data-theme="dark"] [data-icon="transport"] { --cat-bg: rgba(70, 150, 255, 0.18); --cat-fg: #7DB4FF; }
:root[data-theme="dark"] [data-icon="shopping"] { --cat-bg: rgba(255, 90, 150, 0.18); --cat-fg: #FF8DB6; }
:root[data-theme="dark"] [data-icon="bills"] { --cat-bg: rgba(40, 200, 170, 0.18); --cat-fg: #5FD9C0; }
:root[data-theme="dark"] [data-icon="fun"] { --cat-bg: rgba(150, 110, 255, 0.2); --cat-fg: #B49BFF; }
:root[data-theme="dark"] [data-icon="other"] { --cat-bg: rgba(134, 143, 162, 0.19); --cat-fg: #AEB4C1; }
:root[data-theme="dark"] [data-icon="salary"] { --cat-bg: rgba(60, 200, 100, 0.18); --cat-fg: #6EDB8C; }
:root[data-theme="dark"] [data-icon="bonus"] { --cat-bg: rgba(255, 200, 40, 0.18); --cat-fg: #FFD25C; }
:root[data-theme="dark"] [data-icon="side"] { --cat-bg: rgba(110, 125, 255, 0.2); --cat-fg: #9FA9FF; }
:root[data-theme="dark"] [data-icon="other_income"] { --cat-bg: rgba(120, 160, 140, 0.19); --cat-fg: #A3C2B2; }
:root[data-theme="dark"] [data-icon="pet"] { --cat-bg: rgba(170, 81, 215, 0.19); --cat-fg: #C68BE4; }
:root[data-theme="dark"] [data-icon="health"] { --cat-bg: rgba(236, 60, 68, 0.19); --cat-fg: #F27D82; }
:root[data-theme="dark"] [data-icon="home"] { --cat-bg: rgba(160, 145, 90, 0.19); --cat-fg: #CDBE8E; }
:root[data-theme="dark"] [data-icon="gift"] { --cat-bg: rgba(229, 67, 216, 0.19); --cat-fg: #EE81E5; }
:root[data-theme="dark"] [data-icon="travel"] { --cat-bg: rgba(43, 195, 253, 0.19); --cat-fg: #72D7FD; }
:root[data-theme="dark"] [data-icon="education"] { --cat-bg: rgba(186, 247, 49, 0.19); --cat-fg: #D1FA75; }
:root[data-theme="dark"] [data-icon="coffee"] { --cat-bg: rgba(150, 110, 85, 0.19); --cat-fg: #C4A28C; }
:root[data-theme="dark"] [data-icon="phone"] { --cat-bg: rgba(98, 231, 65, 0.19); --cat-fg: #97EF80; }

.home-row-icon[data-icon] { color: var(--cat-fg, var(--secondary-label)); background: var(--cat-bg, var(--fill)); }
.cat-tile[data-icon] .cat-tile-icon { color: var(--cat-fg, var(--secondary-label)); background: var(--cat-bg, var(--fill)); }
.stats-bar-fill[data-icon] { background: var(--cat-fg, var(--secondary-label)); }

/* 高对比：卡片 / 金额列 / 分段控件不再靠淡色底区分，放在文件末尾，才压得过前面的 border-color: transparent；加一圈 token 描边（无阴影） */
@media (prefers-contrast: more) {
  .entry-card:not(.cat-card), .entry-amount-row, .modal-sheet .segmented { border: 1px solid var(--ink-2); }
}
