/* Plain white, dark ink, no boxes: space and weight carry the structure. Colour comes from the category marks
   (a soft tint with a line icon) and one deep green for the main action and for income.
   Inter for Latin and figures (equal-width digits, so amounts line up), Noto Sans SC (Source Han Sans) for Chinese,
   both self-hosted (tools/build_fonts.py); a Chinese character outside the subset falls back to the system font. */

@font-face {
  font-family: "Inter";
  src: url("fonts/inter.woff2?v=8aad6fc3ce") format("woff2");
  font-weight: 400 600;
  font-display: block;
}
@font-face {
  font-family: "Noto Sans SC";
  src: url("fonts/noto-sans-sc.woff2?v=a7b324ff9c") format("woff2");
  font-weight: 400 600;
  font-display: block;
}

:root {
  --bg: #ffffff;        /* the page, and what Safari colours its bars with */
  --surface: #f5f5f3;   /* keys, fields, pills */
  --line: #ececea;
  --ink: #16171a;
  --muted: #6e6e73;
  --bar: #dcdcd8;       /* the daily bars, the sheet handle */
  --accent: #1f5a52;
  --accent-ink: #ffffff;
  --danger: #a33a2c;

  --sans: "Inter", "Noto Sans SC", -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;

  --fs-2xs: 11px;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-ui: 14px;        /* pills and small buttons */
  --fs-body: 15px;
  --fs-field: 16px;     /* typed fields: 16px or more, so iPhone does not zoom in */
  --fs-md: 17px;
  --fs-lg: 21px;
  --fs-xl: 22px;
  --fs-big: 46px;

  --r: 14px;
  --ease: cubic-bezier(.22, .7, .2, 1);
  /* The more directly a motion answers a tap, the quicker */
  --t-press: .12s;      /* a key or pill going down */
  --t-state: .18s;      /* rows making room */
  --t-pick: .32s;       /* the chosen thing settling, the dialog */
  --t-move: .4s;        /* a screen, month or sheet part coming in */
  --t-sheet: .32s;      /* the sheet itself */
  --t-grow: .65s;       /* bars and the ring drawing in */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The page itself never scrolls or bounces; only .scroll inside #app does */
html { -webkit-text-size-adjust: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: 1.45;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  height: 100%;
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }
button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }

#app {
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  --shift: 14px;
}
#app.back { --shift: -14px; }
/* Set by fitScreen in app.js, only when the height above is wrong after the phone was turned */
:root[style*="--app-h"] #app { height: var(--app-h); }
/* The fixed part of a screen; the list below is cut plainly at its edge, no fade (owner, 2026-12-03) */
.fixed { flex: none; position: relative; z-index: 1; background: var(--bg); padding: calc(env(safe-area-inset-top) + 22px) 22px 10px; }
.fixed:empty { display: none; }
.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;  /* only ever up and down, even if something is a hair too wide */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0 22px calc(env(safe-area-inset-bottom) + 116px);
}
.scroll::-webkit-scrollbar { display: none; }
.fixed:empty + .scroll { padding-top: calc(env(safe-area-inset-top) + 22px); }
.scroll > .day:first-child, .scroll > .label:first-child { margin-top: 18px; }
.fixed:empty + .scroll > .label:first-child { margin-top: 0; }
.scroll > .bars:first-child, .scroll > .trend:first-child { margin-top: 12px; }
.scroll > .quick:first-child { margin-top: 14px; }

/* A phone on its side, or a very low window: the fixed top would leave the list no room, so the screen scrolls
   as one (web-dev-lessons.md 4.7: never cut content off) */
@media (max-height: 560px) and (max-width: 559px) {
  #app { display: block; overflow-y: auto; overscroll-behavior: contain; }
  .scroll { overflow: visible; }
}

/* ===== Entering a screen or a month (playEnter in app.js): content slides in from its side, bars grow ===== */
#app.in-page > *,
#app.in-month .total, #app.in-month .sub, #app.in-month .strip, #app.in-month .scroll { animation: slide-in var(--t-move) var(--ease) backwards; }
@keyframes slide-in { from { opacity: 0; transform: translateX(var(--shift)); } }
#app.in-page .strip i, #app.in-month .strip i { transform-origin: 50% 100%; animation: grow-up var(--t-grow) var(--ease) backwards; }
@keyframes grow-up { from { transform: scaleY(0); } }
#app.in-page .fill, #app.in-month .fill { transform-origin: 0 50%; animation: grow-right var(--t-grow) var(--ease) backwards; }
@keyframes grow-right { from { transform: scaleX(0); } }

/* ===== Category marks: a soft tint and a line icon in the same hue ===== */
.mark {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
}
.mark svg { display: block; }
.t-orange { background: #fbf0e4; color: #8a4b12; --chart: #f29555; }
.t-blue { background: #e8f0fa; color: #234f86; --chart: #3a68be; }
.t-rose { background: #f6eaf1; color: #84325e; --chart: #9c2a5b; }
.t-green { background: #e7f2ec; color: #1f5a41; --chart: #2f8f36; }
.t-violet { background: #eeebf8; color: #4c3a94; --chart: #a076e4; }
.t-teal { background: #e3f2f3; color: #16606a; --chart: #37bad0; }
.t-gray { background: #f0f0ee; color: #55555a; --chart: #87888c; }

/* ===== Month header ===== */
.month {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: var(--fs-ui);
  font-weight: 500;
  margin-left: -6px;
}
.month.plain { margin-left: 0; }
.month .step {
  position: relative;
  width: 24px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.month .step::after { content: ""; position: absolute; inset: -8px; }
.month .step:disabled { opacity: .3; }
.month .spacer { flex: 1; }
.month .name { position: relative; color: inherit; font-weight: inherit; min-height: 28px; }
.month .name::after { content: ""; position: absolute; inset: -8px -2px; }
.month .tool { margin-left: 10px; margin-right: -4px; color: var(--ink); }
.month .warn-dot { position: relative; width: 8px; height: 8px; margin-left: 6px; border-radius: 50%; background: var(--danger); }
.month .warn-dot::after { content: ""; position: absolute; inset: -18px; }
.month .side { font-weight: 400; font-size: var(--fs-sm); }
.month .side .num { margin-left: 5px; }
.total { font-size: var(--fs-big); font-weight: 600; line-height: 1.1; margin: 8px 0 2px; letter-spacing: -0.035em; }
.total small { font-size: var(--fs-xl); font-weight: 500; color: var(--muted); margin-right: 3px; letter-spacing: 0; }
.sub { font-size: var(--fs-sm); color: var(--muted); }
.sub .num { margin-left: 5px; font-weight: 500; color: var(--ink); }
.sub .gap { margin-left: 14px; }
.sub.over .num { color: var(--danger); }

/* One bar per day of the month, today's in the accent colour */
.strip { display: flex; align-items: flex-end; gap: 3px; height: 38px; margin-top: 18px; }
.strip i { flex: 1; background: var(--bar); border-radius: 2px; min-height: 2px; }
.strip i.now { background: var(--accent); }
.strip i.none { background: var(--line); height: 2px; }

/* ===== Accounts: figures side by side between two hairlines ===== */
.accounts {
  display: flex;
  margin-top: 18px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}
.accounts::-webkit-scrollbar { display: none; }
.acct { flex: 1 0 auto; min-width: 104px; text-align: left; padding-right: 18px; }
.acct + .acct { border-left: 1px solid var(--line); padding-left: 18px; }
.acct span { display: block; font-size: var(--fs-xs); color: var(--muted); }
.acct b { font-size: var(--fs-md); font-weight: 600; }
/* 后付 accounts: 待还 beside the name or figure; the figure in the warning colour when the due day is near */
.acct span i, .line .v i { font-style: normal; font-size: var(--fs-xs); font-weight: 400; color: var(--muted); }
.acct span i { margin-left: 5px; }
.line .v i { margin-right: 6px; }
.acct.due b, .line.due .v > div { color: var(--danger); }
.line .v { text-align: right; }
.line .v > span { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--muted); }
/* Last month's bill of a 后付 account, with the button that pays it */
.bill { display: flex; align-items: center; gap: 12px; margin-top: 14px; padding: 10px 10px 10px 16px; background: var(--surface); border-radius: var(--r); }
.bill div { flex: 1; display: grid; }
.bill span { font-size: var(--fs-2xs); color: var(--muted); }
.bill b { font-size: var(--fs-md); font-weight: 600; }
.bill .btn { flex: none; min-height: 44px; padding: 0 22px; }

/* ===== Section labels ===== */
/* Spacing rhythm (2026-12-01): 30px before a section label and 6px after it, 18px between the blocks of a fixed
   top, 14px between a list and the action under it (.under, .btns), 14px between the parts of a sheet */
.label { font-size: var(--fs-xs); color: var(--muted); margin: 30px 0 6px; letter-spacing: .05em; }
.under { margin-top: 14px; }
/* A list row carries about 16px of its own space under its text, so what follows a list sits closer */
.rows + .label { margin-top: 16px; }
.rows + .btns { margin-top: 2px; }
.rows + .foot { margin-top: 34px; }
.under .q { background: none; }

/* ===== Regular places: a row of pills ===== */
.quick, .chips {
  display: flex;
  gap: 8px;
  margin: 16px -22px 0;
  padding: 0 22px;
  overflow-x: auto;
  scrollbar-width: none;
}
.quick::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.q, .chip {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0 14px;
  min-height: 38px;
  font-size: var(--fs-ui);
  font-weight: 500;
  white-space: nowrap;
  transition: transform var(--t-press);
}
.q:active, .chip:active { transform: scale(.96); }
.q em { font-style: normal; font-weight: 400; font-size: var(--fs-xs); color: var(--muted); margin-left: 6px; }
.q.new { color: var(--muted); border-style: dashed; font-weight: 400; }

/* ===== Days and entries ===== */
.day {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--fs-sm);
  color: var(--muted);
  margin: 26px 0 4px;
}
.day b { font-weight: 600; color: var(--ink); margin-right: 6px; }
.row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: calc(100% + 20px);
  margin: 0 -10px;
  padding: 9px 10px;
  text-align: left;
  background: var(--bg);
  border-radius: var(--r);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  position: relative;
}
.row .t { flex: 1; min-width: 0; }
.row .t b {
  display: block;
  font-size: var(--fs-body);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row .t span, .row .side span { display: block; font-size: var(--fs-xs); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { flex: none; max-width: 46%; text-align: right; }
.row .amt { font-size: var(--fs-field); font-weight: 500; }
.row .amt.plus { color: var(--accent); }
.row .amt.soft { color: var(--muted); font-weight: 400; }
/* Reordering: the held row lifts and follows the finger, the others make room (entries and accounts) */
.line[data-id] { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; position: relative; }
.rows.sorting .line { transition: transform var(--t-state) var(--ease); }
.line.lifted { z-index: 2; background: var(--bg); border-radius: var(--r); border-top-color: transparent; box-shadow: 0 8px 24px rgba(0, 0, 0, .14); transition: none !important; }
.line.lifted + .line { border-top-color: transparent; }
.list.sorting .row { transition: transform var(--t-state) var(--ease); }
/* No grey on a pressed row (owner, 2026-12-03): the sheet opens at once, and in a scroll it flashed on the row under the finger */
.row.lifted {
  z-index: 2;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  transition: none !important;
}
.empty { color: var(--muted); font-size: var(--fs-sm); margin: 28px 0; }
.empty.big { display: grid; justify-items: center; gap: 14px; margin: 64px 0; font-size: var(--fs-body); }

/* ===== Stats ===== */
.bars { margin-top: 22px; }
.bar { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; padding: 9px 0; flex-wrap: wrap; }
.bar .body { flex: 1; min-width: 0; }
.bar .top { display: flex; align-items: baseline; gap: 10px; }
.bar .name { flex: 1; font-weight: 500; }
.bar .pct { color: var(--muted); font-size: var(--fs-sm); }
.bar .val { font-weight: 500; min-width: 76px; text-align: right; }
.bar .track { height: 4px; background: var(--surface); border-radius: 2px; margin-top: 7px; overflow: hidden; }
.bar .fill { display: block; height: 100%; background: var(--chart) !important; border-radius: 2px; }
/* An open category: its subcategories in one wrapping line, then its entries */
.detail { padding: 2px 0 14px; }
.detail .subs { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 2px 0 8px 52px; font-size: var(--fs-sm); color: var(--muted); }
.detail .subs div { display: flex; gap: 6px; }
.detail .subs .num { color: var(--ink); }

/* Six months of spending: the month shown is dark, the others quiet */
.trend { display: grid; grid-template-columns: repeat(6, 1fr); align-items: end; gap: 6px; margin: 4px 0 18px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.trend button { display: grid; justify-items: center; gap: 5px; color: var(--muted); font-size: var(--fs-2xs); }
.trend i { display: block; width: 100%; max-width: 30px; background: var(--bar); border-radius: 3px 3px 0 0; }
.trend em { font-style: normal; }
.trend .on { color: var(--ink); font-weight: 600; }
.trend .on i { background: var(--ink); }
#app.in-page .trend i, #app.in-month .trend i { transform-origin: 50% 100%; animation: grow-up var(--t-grow) var(--ease) backwards; }

/* ===== Plain lists (accounts, places, settings) ===== */
.line {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 54px;
  padding: 10px 0;
  text-align: left;
}
.line + .line { border-top: 1px solid var(--line); }
.line .t { flex: 1; min-width: 0; font-weight: 500; }
.line .t span { display: block; font-size: var(--fs-xs); font-weight: 400; color: var(--muted); }
.line .parts span { display: inline; }
.line .parts span + span { margin-left: 8px; }
.line .v { font-weight: 500; }
.line.off { color: var(--muted); }
.link { color: var(--accent); font-size: var(--fs-body); padding: 12px 0; min-height: 44px; }
.link.danger { color: var(--danger); }
.code {
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-lg);
  font-weight: 500;
  letter-spacing: .12em;
  padding: 6px 0 2px;
}
.note { font-size: var(--fs-sm); color: var(--muted); padding: 10px 0 0; }
.foot { margin-top: 48px; text-align: center; font-size: var(--fs-xs); color: var(--muted); }

/* ===== Tab bar: plain white, no border, no shadow and no fade (owner, 2026-12-03); the add button is flat ===== */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  background: var(--bg);
  display: grid;
  grid-template-columns: 1fr 1fr 76px 1fr 1fr;
  align-items: center;
  max-width: 480px;
  margin: 0 auto;
  padding: 4px 14px calc(env(safe-area-inset-bottom) + 10px);
}
.tab {
  text-align: center;
  font-size: var(--fs-2xs);
  color: var(--muted);
  min-height: 46px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 3px;
}
.tab svg { display: block; }
.tab.on { color: var(--ink); font-weight: 600; }
.add {
  justify-self: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  transition: transform var(--t-press);
}
.add:active { transform: scale(.94); }

/* ===== Sheet: always in the page, moved only by transform (web-dev-lessons.md 6.4) ===== */
/* The shade is clear (owner, 2026-12-03): it only catches a tap outside the sheet. A dark shade tinted iPhone's status
   bar, which lagged behind the page when the sheet closed; the sheet is set apart by its shadow instead */
.shade { position: fixed; inset: 0; z-index: 20; }
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 21;
  max-width: 480px;
  margin: 0 auto;
  max-height: 94svh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -6px 32px rgba(0, 0, 0, .12), 0 -1px 0 rgba(0, 0, 0, .04);
  padding: 10px 20px calc(env(safe-area-inset-bottom) + 16px);
  transform: translateY(110%);
  /* Hidden for real when not shown, a moment after it has slid away: turning the phone switches between the phone
     and wide ways of hiding it, and in between it could glide through view (the flash when turning upright) */
  visibility: hidden;
  transition: transform var(--t-sheet) var(--ease), visibility 0s var(--t-sheet);
  will-change: transform;  /* its own layer from the start, so the first frames of the slide are not spent making one */
}
.sheet.show { transform: none; visibility: visible; transition: transform var(--t-sheet) var(--ease), visibility 0s; }
/* Set by holdStill in app.js while the phone turns */
.turning .sheet, .turning .shade, .turning .toast { transition: none !important; }
.handle { width: 36px; height: 4px; background: var(--bar); border-radius: 2px; margin: 0 auto 14px; }
.sheet h2 { font-size: var(--fs-md); font-weight: 600; margin: 2px 0 14px; }
.sheet .chips { margin: 14px -20px 0; padding: 0 20px; }

/* Type switch: words with a line under the chosen one; date and account sit to its right */
.head { display: flex; align-items: center; gap: 10px; min-height: 36px; }
.seg { display: flex; gap: 20px; flex: none; }
.seg button { position: relative; padding: 6px 0; color: var(--muted); }
.seg button::before { content: ""; position: absolute; inset: -4px -8px; }
.seg .on { color: var(--ink); font-weight: 600; }
.seg .ink {
  transform-origin: 0 50%;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
}
.meta { flex: 1; min-width: 0; display: flex; justify-content: flex-end; align-items: center; gap: 5px; color: var(--muted); }
.pick {
  position: relative;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 112px;
  min-height: 32px;
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: 999px;
  padding: 0 11px;
  font-size: var(--fs-sm);
  color: var(--ink);
}
.pick.date { flex: none; }
.pick.date::after, .chips.subs .chip::after { content: ""; position: absolute; inset: -6px 0; }
/* The account pill's own control is the system list, so the list itself is made taller, not covered */
.pick select { top: -6px; height: calc(100% + 12px); }
.pick span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick select, .pick input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: var(--fs-field);
  border: 0;
  padding: 0;
  margin: 0;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
/* The places row in the entry sheet: the pills scroll, the 不计支出 switch stays at the right end */
.place-line { display: flex; align-items: center; gap: 4px; margin: 14px -20px 0; padding-right: 20px; }
.place-line .chips { flex: 1; min-width: 0; margin: 0; padding: 0 20px; }
.nb { flex: none; display: flex; align-items: center; gap: 6px; min-height: 38px; font-size: var(--fs-sm); color: var(--muted); }
.nb i { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--bar); transition: background var(--t-press), border-color var(--t-press); }
.nb.on { color: var(--ink); font-weight: 500; }
.nb.on i { border: 4px solid var(--accent); }
/* Subcategories: equal pills; the chosen one takes its category's tint */
.chips.subs { gap: 6px; min-height: 32px; }
.chips.subs .chip {
  position: relative;
  flex: 1 1 0;
  border: 0;
  padding: 0 4px;
  min-height: 32px;
  font-size: var(--fs-sm);
  font-weight: 400;
  text-align: center;
  background: var(--surface);
  color: var(--muted);
}
.chips.subs .chip.on { font-weight: 600; box-shadow: inset 0 0 0 1.5px currentColor; }
.chips.subs .chip.on.t-orange { background: #fbf0e4; color: #8a4b12; }
.chips.subs .chip.on.t-blue { background: #e8f0fa; color: #234f86; }
.chips.subs .chip.on.t-rose { background: #f6eaf1; color: #84325e; }
.chips.subs .chip.on.t-green { background: #e7f2ec; color: #1f5a41; }

.amount {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.amount input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 6px 0;
  font-size: var(--fs-md);  /* 16px or more: iPhone does not zoom into the field */
  font-weight: 500;
  border-radius: 0;
  outline: none;
}
.amount input::placeholder { color: var(--muted); font-weight: 400; }
.amount .v { font-size: var(--fs-big); font-weight: 600; line-height: 1; letter-spacing: -0.035em; white-space: nowrap; margin-left: auto; }
.amount .v small { font-size: var(--fs-xl); font-weight: 500; color: var(--muted); margin-right: 3px; letter-spacing: 0; }
.amount .v.zero { color: var(--muted); }
/* A sum being typed (12.5+3−1) is longer than a figure: smaller, so the text field beside it keeps its room */
.amount .v.sum { font-size: var(--fs-xl); letter-spacing: 0; line-height: 1.6; }
.amount .v.sum small { font-size: var(--fs-ui); }
.amount .v.shake, .cats.shake { animation: shake .5s; }
@keyframes shake { 15% { transform: translateX(-8px); } 35% { transform: translateX(7px); } 55% { transform: translateX(-5px); } 75% { transform: translateX(3px); } }

.cats { display: grid; grid-template-columns: repeat(7, 1fr); margin-top: 14px; }
.cats.four { grid-template-columns: repeat(4, 1fr); }
.cats.kinds { margin: 2px 0 14px; }
.cat { text-align: center; font-size: var(--fs-2xs); color: var(--muted); padding: 2px 0; }
.cat .mark { margin: 0 auto 5px; transition: box-shadow var(--t-press); }
.cat.on { color: var(--ink); font-weight: 600; }
.cat.on .mark { box-shadow: 0 0 0 1.5px currentColor; }
/* Save pressed with no category chosen: the categories turn red for a moment while they shake (owner, 2026-12-03) */
.cats .cat { transition: color var(--t-state); }
.cats.need .cat { color: var(--danger); }
.cats.need .cat .mark { box-shadow: 0 0 0 1.5px var(--danger); }

/* Labelled fields of the smaller sheets (account, place, sync code) */
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.field {
  position: relative;
  background: var(--surface);
  border-radius: 12px;
  padding: 7px 12px;
  min-height: 50px;
}
.field span { display: block; font-size: var(--fs-2xs); color: var(--muted); }
.field select, .field input {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  font-size: var(--fs-field);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-height: 22px;
}
.field.wide { grid-column: 1 / -1; }

.keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-top: 14px; }
.k {
  background: var(--surface);
  border-radius: var(--r);
  height: 48px;
  display: grid;
  place-items: center;
  font-size: var(--fs-lg);
  transition: background var(--t-press), transform var(--t-press);
}
.k:active { background: var(--line); transform: scale(.95); }
.k.fn { font-size: var(--fs-ui); color: var(--muted); }
.k.del { color: var(--danger); }
.k.save {
  background: var(--accent);
  color: var(--accent-ink);
  font-size: var(--fs-field);
  font-weight: 600;
}
.k.save:active { background: #174640; }
.k svg { display: block; }

.btns { display: flex; gap: 8px; margin-top: 14px; }
.btns.first { margin-top: 8px; }
.btns.three .btn { font-size: var(--fs-ui); padding: 0 4px; }
.btn.warn { color: var(--danger); }
.btn {
  flex: 1;
  min-height: 48px;
  border-radius: var(--r);
  background: var(--surface);
  font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }

/* ===== One sentence in ===== */
.ask { margin-bottom: 12px; }
.ask-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-radius: var(--r);
  padding: 0 6px 0 14px;
  height: 46px;
}
.ask-row input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0;
  font-size: var(--fs-field);
  outline: none;
}
.ask-row input::placeholder { color: var(--muted); }
.ask-go {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
}
.ask-go:disabled { animation: wait 1s ease-in-out infinite; }
@keyframes wait { 50% { opacity: .35; } }
.batch { margin-top: 4px; }
/* The batch list keeps day, subcategory and account on one line under the name, apart by spacing */
.batch .row .t div { display: flex; gap: 10px; min-width: 0; }
.batch .row .t div span { flex: none; }
/* A row of the batch list opens that entry */
.row.tap { cursor: pointer; }
.drop { flex: none; width: 32px; height: 32px; margin-right: -6px; color: var(--muted); font-size: var(--fs-lg); position: relative; }
.drop::after { content: ""; position: absolute; inset: -6px; }
.note.sum { text-align: right; }
.note.sum .num { margin-left: 6px; color: var(--ink); font-weight: 500; }
.line .v.state { font-weight: 400; color: var(--muted); }

/* ===== Small centred dialog for confirmations ===== */
.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 31;
  width: min(320px, calc(100% - 48px));
  transform: translate(-50%, -50%);
  background: var(--bg);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .18);
  padding: 20px 18px 16px;
}
.dialog h3 { margin: 0 0 6px; font-size: var(--fs-md); }
.dialog p { margin: 0; color: var(--muted); font-size: var(--fs-sm); }
.dialog .btns { flex-direction: column; }
.dialog-shade { z-index: 30; }

/* ===== Stats ring: slices in the chart colours (--chart on the .t-* classes; the set passes the dataviz palette
   check for every pair, also for colour-blind readers), 2.5px gaps, the total in the middle ===== */
.donut { position: relative; width: 172px; height: 172px; margin: 10px auto 2px; }
.donut svg { display: block; width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .seg { stroke: var(--chart); background: none; }
.donut .seg.dim { opacity: .22; }
.donut .hit { stroke: transparent; pointer-events: stroke; cursor: pointer; }
.donut .mid { position: absolute; inset: 0; display: grid; align-content: center; justify-items: center; pointer-events: none; }
.donut .mid span { font-size: var(--fs-xs); color: var(--muted); }
.donut .mid span i { font-style: normal; margin-left: 5px; }
.donut .mid b { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.25; }
.donut .mid.long b { font-size: var(--fs-md); }
.donut .mid small { font-size: var(--fs-sm); font-weight: 500; color: var(--muted); margin-right: 2px; }
#app.in-page .donut svg, #app.in-month .donut svg { animation: ring-in var(--t-grow) var(--ease) backwards; }
@keyframes ring-in { from { opacity: 0; transform: rotate(-150deg) scale(.9); } }
#app.in-page .donut .mid, #app.in-month .donut .mid { animation: shade-in var(--t-move) var(--t-state) var(--ease) backwards; }

/* ===== The sheet's own calendar ===== */
.cal-top { display: flex; align-items: center; gap: 4px; min-height: 36px; }
.cal-top b { font-weight: 600; margin: 0 4px; }
.cal-top .step { position: relative; width: 28px; height: 32px; display: grid; place-items: center; color: var(--muted); }
.cal-top .step::after { content: ""; position: absolute; inset: -6px; }
.cal-top .spacer { flex: 1; }
.cal-top .link { padding: 0; min-height: 36px; color: var(--muted); }
.sheet .chips.cal-near { margin-top: 10px; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 2px; margin-top: 14px; justify-items: center; }
.cal i { font-style: normal; font-size: var(--fs-xs); color: var(--muted); height: 26px; }
.cal .d {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-variant-numeric: tabular-nums;
  transition: background var(--t-press);
}
.cal .d:active { background: var(--surface); }
.cal .d.now { border: 1.5px solid var(--line); font-weight: 600; }
.cal .d.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; border: 0; }
.cal .d.has::after { content: ""; position: absolute; left: 50%; bottom: 6px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: var(--bar); }
.cal .d.on.has::after { background: rgba(255, 255, 255, .7); }

/* ===== Motion inside the sheet (owner, 2026-12-01: more of it and slower). redrawSheet(fx) names what changed and
   only that part moves; nothing ever grows past its final size =====
   fx-open   the sheet slides up and its parts follow one after another
   fx-type   the content slides the way the type switch went (the line under the words slides in app.js)
   fx-cat    the chosen mark settles, the subcategories come in one by one
   fx-sub    the chosen pill settles
   fx-cal / fx-back   the calendar and the form change places
   fx-step   the calendar's month slides the way it lies
   fx-again  after 再记, the emptied form settles */
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes settle { from { transform: scale(.82); opacity: .3; } }
@keyframes fade { from { opacity: 0; } }
.sheet { --shift: 22px; }

.sheet.fx-open > :not(.handle) { animation: rise var(--t-move) var(--ease) backwards; }
.sheet.fx-open > :nth-child(2) { animation-delay: .04s; }
.sheet.fx-open > :nth-child(3) { animation-delay: .07s; }
.sheet.fx-open > :nth-child(4) { animation-delay: .1s; }
.sheet.fx-open > :nth-child(5) { animation-delay: .13s; }
.sheet.fx-open > :nth-child(6) { animation-delay: .16s; }
.sheet.fx-open > :nth-child(n + 7) { animation-delay: .19s; }

.sheet.fx-type .chips, .sheet.fx-type .amount, .sheet.fx-type .cats { animation: slide-in var(--t-move) var(--ease) backwards; }
.sheet.fx-type .amount { animation-delay: .04s; }
.sheet.fx-type .cats { animation-delay: .08s; }
.sheet.fx-type .chips.subs { animation-delay: .12s; }
.sheet.fx-type .meta { animation: fade var(--t-move) var(--ease) backwards; }

.sheet.fx-cat .cat.on .mark { animation: settle var(--t-pick) var(--ease) backwards; }
.sheet.fx-cat .cat.on { animation: fade var(--t-pick) var(--ease) backwards; }
.sheet.fx-cat .chip.on, .sheet.fx-sub .chip.on { animation: settle var(--t-pick) var(--ease) backwards; }
.sheet.fx-cat .chips.subs .chip:not(.on) { animation: rise var(--t-pick) var(--ease) backwards; }
.sheet.fx-cat .chips.subs .chip:nth-child(2) { animation-delay: .04s; }
.sheet.fx-cat .chips.subs .chip:nth-child(3) { animation-delay: .08s; }
.sheet.fx-cat .chips.subs .chip:nth-child(4) { animation-delay: .12s; }
.sheet.fx-cat .chips.subs .chip:nth-child(5) { animation-delay: .16s; }
.sheet.fx-cat .chips.subs .chip:nth-child(n + 6) { animation-delay: .2s; }

.sheet.fx-cal > :not(.handle), .sheet.fx-back > :not(.handle) { animation: rise var(--t-move) var(--ease) backwards; }
.sheet.fx-cal > :nth-child(3), .sheet.fx-back > :nth-child(3) { animation-delay: .05s; }
.sheet.fx-cal > :nth-child(n + 4), .sheet.fx-back > :nth-child(n + 4) { animation-delay: .1s; }
.sheet.fx-cal .cal .d.on, .sheet.fx-back .pick.date { animation: settle var(--t-move) .1s var(--ease) backwards; }
.sheet.fx-step .cal { animation: slide-in var(--t-move) var(--ease) backwards; }
.sheet.fx-step .cal-top b { animation: fade var(--t-pick) var(--ease) backwards; }

.sheet.fx-again .amount, .sheet.fx-again .cats, .sheet.fx-again .chips { animation: rise var(--t-move) var(--ease) backwards; }

/* The digit just typed rises into place */
.amount .v .new { display: inline-block; animation: digit var(--t-state) var(--ease) backwards; }
@keyframes digit { from { opacity: 0; transform: translateY(35%); } }

/* The row saved a moment ago: it arrives on a soft ground that fades back to the page */
.row.born { animation: born 1.1s var(--ease) backwards; }
@keyframes born {
  0% { opacity: 0; transform: translateY(12px); background: var(--surface); }
  35% { opacity: 1; transform: none; background: var(--surface); }
  100% { background: var(--bg); }
}

/* The confirmation dialog and its shade arrive softly instead of popping in */
.dialog { animation: dialog-in var(--t-pick) var(--ease) backwards; }
@keyframes shade-in { from { opacity: 0; } }
@keyframes dialog-in { from { opacity: 0; transform: translate(-50%, -46%) scale(.96); } }

@media (hover: hover) {
  .row:hover { background: var(--surface); }
}
/* Motion always plays, whatever the phone's reduce-motion setting (owner, 2026-12-01) */

/* The sync code on its own sheet */
.code.big { font-size: var(--fs-xl); text-align: center; padding: 18px 0 10px; letter-spacing: .08em; }
.btn:disabled { opacity: .5; }

/* ===== Wide screens: computer, iPad, and a phone on its side (owner, 2026-12-02) =====
   The tab bar becomes a rail on the left, the fixed top and the list sit side by side as two panes that scroll on
   their own, and sheets are centred cards instead of rising from the bottom edge. */
@media (min-width: 760px), (orientation: landscape) and (min-width: 560px) {
  :root { --rail: 84px; --pane-top: 40px; }
  #app {
    display: grid;
    grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    max-width: 1080px;
    padding-left: calc(var(--rail) + env(safe-area-inset-left));
    padding-right: env(safe-area-inset-right);
  }
  .fixed {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    padding: var(--pane-top) 28px 28px 22px;
  }
  .fixed::-webkit-scrollbar { display: none; }
  .scroll { padding: var(--pane-top) 28px 40px; border-left: 1px solid var(--line); }
  .scroll > .day:first-child, .scroll > .label:first-child, .scroll > .bars:first-child { margin-top: 0; }
  /* Settings has no fixed part: one column of comfortable width */
  .fixed:empty + .scroll { grid-column: 1 / -1; max-width: 600px; padding-top: var(--pane-top); padding-left: 22px; border-left: 0; }
  .donut { width: 220px; height: 220px; margin-top: 28px; }
  .donut .mid b { font-size: var(--fs-xl); }

  /* The rail: the add button on top, the four screens under it */
  .tabbar {
    top: 0;
    bottom: 0;
    right: auto;
    left: max(0px, calc(50vw - 540px));
    width: calc(var(--rail) + env(safe-area-inset-left));
    max-width: none;
    margin: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: var(--pane-top) 0 16px env(safe-area-inset-left);
    border-right: 1px solid var(--line);
  }
  .tab { width: 64px; min-height: 58px; border-radius: var(--r); }
  .add { order: -1; margin: 0 0 18px; width: 52px; height: 52px; }

  /* Sheets: a centred card that fades up into place */
  .sheet {
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(440px, calc(100vw - 48px));
    max-width: none;
    max-height: calc(100svh - 32px);
    margin: 0;
    border-radius: 26px;
    padding: 22px 24px 24px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .18);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, calc(-50% + 18px)) scale(.98);
    transition: transform var(--t-sheet) var(--ease), opacity var(--t-state) var(--ease), visibility 0s var(--t-sheet);
    scrollbar-width: none;
  }
  .sheet::-webkit-scrollbar { display: none; }
  .sheet.show { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%);
    transition: transform var(--t-sheet) var(--ease), opacity var(--t-state) var(--ease), visibility 0s; }
  .handle { display: none; }
  .sheet .chips { margin-left: -24px; margin-right: -24px; padding: 0 24px; }
  .place-line { margin-left: -24px; margin-right: -24px; padding-right: 24px; }
  .place-line .chips { margin: 0; padding: 0 24px; }
}

/* Wide and low (a phone on its side): tighter panes, and the entry sheet puts its keys beside the form so that
   everything fits the height */
@media (orientation: landscape) and (min-width: 560px) and (max-height: 560px) {
  :root { --rail: 68px; --pane-top: 16px; --fs-big: 36px; }
  #app { grid-template-columns: minmax(240px, 42%) minmax(0, 1fr); }
  .fixed { padding: var(--pane-top) 18px 16px 16px; }
  .scroll { padding: var(--pane-top) 18px 24px; }
  .total { margin-top: 4px; }
  .strip { height: 28px; margin-top: 12px; }
  .accounts { margin-top: 12px; padding: 10px 0; }
  .quick { margin: 12px -18px 0; padding: 0 18px; }  /* the pane's padding here is 18px, not 22px */
  .donut { width: 150px; height: 150px; margin-top: 10px; }
  .donut .mid b { font-size: var(--fs-md); }
  .tab { min-height: 48px; gap: 2px; }
  .tabbar { gap: 2px; padding-top: 10px; padding-bottom: 6px; }
  .add { width: 44px; height: 44px; margin-bottom: 6px; }

  .sheet { padding: 14px 20px 16px; max-height: calc(100svh - 16px); }
  .sheet:has(.keys) {
    width: min(720px, calc(100vw - 32px));
    display: grid;
    grid-template-columns: minmax(0, 1fr) 280px;
    column-gap: 22px;
    align-content: start;
  }
  .sheet:has(.keys) > * { grid-column: 1; }
  .sheet:has(.keys) > .keys { grid-column: 2; grid-row: 1 / span 12; align-self: center; margin-top: 0; }
  .k { height: 44px; }
  .amount { margin-top: 10px; padding-bottom: 6px; }
  .cats { margin-top: 10px; }
  .sheet .chips { margin-top: 10px; }
  .cal { margin-top: 6px; row-gap: 0; }
  .cal .d { width: 34px; height: 34px; }
  .cal i { height: 20px; }
}

@media (hover: hover) {
  .tab:hover, .line[data-id]:hover, button.line:hover { background: var(--surface); }
  button.line { border-radius: 0; }
  .k:hover { background: var(--line); }
  .q:hover, .chip:not(.on):hover, .pick:hover, .btn:not(.primary):hover { background: var(--line); }
  .cal .d:not(.on):hover { background: var(--surface); }
  .add:hover { transform: scale(1.04); }
}

/* A short line at the bottom with one way back; it floats above the tab bar and never touches an edge */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 44px;
  padding: 0 8px 0 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: var(--fs-ui);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: transform var(--t-pick) var(--ease), opacity var(--t-state) var(--ease);
}
.toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.toast button { color: #fff; font-weight: 600; min-height: 44px; padding: 0 12px; border-left: 1px solid rgba(255, 255, 255, .22); }

/* What was said, kept beside what was understood */
.note.said { padding: 0 0 8px; }

/* The account chosen in the sheet's own list */
.line.chosen .t { color: var(--accent); font-weight: 600; }

/* Month choice: the calendar's grid with twelve months */
.cal.months { grid-template-columns: repeat(4, 1fr); row-gap: 10px; margin-bottom: 8px; }
.cal.months .d { width: 64px; height: 44px; border-radius: 999px; }
.cal .d:disabled { color: var(--bar); }

/* Search: the field, then what was found */
.ask-row.search { margin-bottom: 6px; }
.found { min-height: 40vh; }
.found .day { margin-top: 18px; }
.found .note.sum { padding-top: 6px; }

@media (min-width: 760px), (orientation: landscape) and (min-width: 560px) {
  .scroll > .quick:first-child { margin-top: 0; }
  .scroll > .trend:first-child { margin-top: 0; }
}

@media (min-width: 760px), (orientation: landscape) and (min-width: 560px) {
  .toast { bottom: 32px; }
}
