/* ============================================================
   SketchLedger · 手绘账本
   视觉系统：暖色纸张 + 抖动描边 + 蜡笔色 + 贴纸感
   ============================================================ */

@font-face {
  font-family: "Patrick Hand";
  src: url("fonts/PatrickHand-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+2000-206F, U+20A0-20CF, U+2100-214F;
}

/* ---------- 1. 设计变量 ---------- */
:root {
  --paper: #FFF9EE;
  --paper-2: #FFF3DF;
  --card: #FFFDF7;
  --card-2: #FFF7E8;
  --ink: #332E28;
  --ink-2: #6F6858;
  --ink-3: #9C9486;
  --line: rgba(51, 46, 40, 0.14);
  --line-strong: rgba(51, 46, 40, 0.4);
  --red: #E8563F;
  --orange: #F09A38;
  --yellow: #EFC03B;
  --green: #2FAE84;
  --blue: #4A90D9;
  --purple: #8E77D9;
  --pink: #E06A8C;
  --shadow-sm: 2px 3px 0 rgba(51, 46, 40, 0.10);
  --shadow: 3px 5px 0 rgba(51, 46, 40, 0.13);
  --shadow-lg: 5px 7px 0 rgba(51, 46, 40, 0.15);
  --radius: 18px;
  --tabbar-h: 62px;
  --font-hand: "Patrick Hand", "Kaiti SC", "STKaiti", KaiTi, "楷体", "Songti SC", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, sans-serif;
}

[data-theme="dark"] {
  --paper: #1F1B18;
  --paper-2: #262119;
  --card: #2A2521;
  --card-2: #332C25;
  --ink: #F6EDDD;
  --ink-2: #C4B8A4;
  --ink-3: #8E8474;
  --line: rgba(246, 237, 221, 0.14);
  --line-strong: rgba(246, 237, 221, 0.42);
  --red: #F0715C;
  --orange: #F2A64F;
  --yellow: #F3CB57;
  --green: #3FC79A;
  --blue: #6BA6E4;
  --purple: #A491E6;
  --pink: #EC7E9E;
  --shadow-sm: 2px 3px 0 rgba(0, 0, 0, 0.35);
  --shadow: 3px 5px 0 rgba(0, 0, 0, 0.38);
  --shadow-lg: 5px 7px 0 rgba(0, 0, 0, 0.42);
}

/* ---------- 2. 基础 ---------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  background: var(--paper);
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1100px 520px at 8% -8%, var(--paper-2) 0%, transparent 62%),
    radial-gradient(760px 420px at 108% 4%, rgba(224, 106, 140, 0.10) 0%, transparent 58%),
    radial-gradient(820px 620px at 50% 118%, rgba(47, 174, 132, 0.09) 0%, transparent 62%),
    var(--paper);
  background-attachment: fixed;
  overscroll-behavior-y: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  padding: 0;
}

/* 纸张颗粒 */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.055;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}
[data-theme="dark"] body::after {
  mix-blend-mode: screen;
  opacity: 0.04;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

ul, ol { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, p { margin: 0; }

input, textarea {
  border: 0;
  background: transparent;
  outline: none;
  -webkit-appearance: none;
  border-radius: 0;
}

::selection { background: rgba(239, 192, 59, 0.45); }

.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- 3. 外壳 ---------- */
.app {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: max(6px, env(safe-area-inset-top)) 0 calc(var(--tabbar-h) + 64px + env(safe-area-inset-bottom));
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px 2px;
}

.brand {
  font-family: var(--font-hand);
  font-size: 22px;
  letter-spacing: 0.02em;
  line-height: 1.1;
  display: inline-block;
  padding: 0 2px;
  background: linear-gradient(transparent 58%, rgba(239, 192, 59, 0.55) 58%, rgba(239, 192, 59, 0.55) 92%, transparent 92%);
}

.brand-sub {
  display: block;
  font-size: 10px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
  margin-top: 1px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  color: var(--ink);
  border: 2px solid transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn:hover { border-color: var(--line); }

/* 月份切换 */
.monthbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 16px 12px;
}

.monthbar__nav {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-family: var(--font-hand);
  font-size: 21px;
  color: var(--ink-2);
  display: grid;
  place-items: center;
  border: 2px solid transparent;
  transition: transform 0.12s ease;
}
.monthbar__nav:active { transform: scale(0.88); background: var(--line); }
.monthbar__nav[disabled] { opacity: 0.28; }

.monthbar__label {
  font-family: var(--font-hand);
  font-size: 19px;
  letter-spacing: 0.04em;
  padding: 0 6px 2px;
  border-bottom: 2px dashed var(--line-strong);
  color: var(--ink);
}

/* 视图 */
.main { padding: 0 14px; }

.view { animation: viewIn 0.26s ease both; }
.view[hidden] { display: none; }

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 4. 卡片 / 贴纸 / 按钮 ---------- */
.card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius) calc(var(--radius) + 5px) calc(var(--radius) - 3px) calc(var(--radius) + 7px) /
    calc(var(--radius) + 6px) calc(var(--radius) - 4px) calc(var(--radius) + 4px) calc(var(--radius) - 2px);
  box-shadow: var(--shadow);
  padding: 16px;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2.2px solid var(--ink);
  border-radius: inherit;
  filter: url(#wobble-soft);
  pointer-events: none;
  opacity: 0.92;
}

.card--plain::before { border-color: var(--line-strong); border-width: 1.8px; }

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-hand);
  font-size: 17px;
  letter-spacing: 0.02em;
  color: var(--ink);
  margin: 22px 4px 10px;
}
.section-title::after {
  content: "";
  flex: 1;
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--line-strong) 0 6px, transparent 6px 11px);
  border-radius: 2px;
  opacity: 0.55;
}

.tape {
  position: absolute;
  width: 74px;
  height: 22px;
  background: rgba(239, 192, 59, 0.55);
  border-left: 1px dashed rgba(255, 255, 255, 0.5);
  border-right: 1px dashed rgba(255, 255, 255, 0.5);
  transform: rotate(-4deg);
  box-shadow: 0 1px 2px rgba(51, 46, 40, 0.10);
  pointer-events: none;
}
[data-theme="dark"] .tape { background: rgba(239, 192, 59, 0.3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 0 18px;
  white-space: nowrap;
  font-family: var(--font-hand);
  font-size: 18px;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--card);
  border: 2.2px solid var(--ink);
  border-radius: 14px 17px 13px 18px / 17px 13px 18px 14px;
  box-shadow: 0 3px 0 var(--line-strong);
  transition: transform 0.1s ease, box-shadow 0.1s ease, background 0.15s ease;
}
.btn:active { transform: translateY(3px); box-shadow: none; }
.btn--primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
  box-shadow: 0 3px 0 rgba(51, 46, 40, 0.35);
}
.btn--accent { background: var(--yellow); }
.btn--danger { color: var(--red); border-color: var(--red); box-shadow: 0 3px 0 rgba(232, 86, 63, 0.35); }
.btn--ghost { box-shadow: none; border-color: var(--line-strong); background: transparent; }
.btn--sm { min-height: 38px; font-size: 15px; padding: 0 12px; }
.btn--block { width: 100%; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-hand);
  font-size: 15px;
  padding: 5px 11px;
  border: 1.8px solid var(--line-strong);
  border-radius: 12px 9px 13px 10px;
  color: var(--ink-2);
  background: var(--card);
}
.chip.is-on { color: var(--ink); border-color: var(--ink); background: rgba(239, 192, 59, 0.3); }

/* ---------- 5. 首页 ---------- */
.hero {
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(239, 192, 59, 0.16), transparent 60%),
    var(--card);
  padding: 18px 18px 14px;
}

.hero__tape { top: -9px; left: 50%; margin-left: -37px; transform: rotate(-3deg); }

.hero__label {
  font-family: var(--font-hand);
  font-size: 15px;
  color: var(--ink-2);
  letter-spacing: 0.06em;
}

.hero__amount {
  font-family: var(--font-hand);
  font-size: clamp(44px, 15vw, 58px);
  line-height: 1.02;
  margin: 2px 0 2px -2px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.hero__amount .cur { font-size: 0.48em; opacity: 0.6; margin-right: 2px; vertical-align: 0.22em; }
.hero__amount .dec { font-size: 0.56em; opacity: 0.75; }

.hero__meta {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed var(--line);
}
.hero__meta > div { flex: 1; }
.hero__meta b {
  display: block;
  font-family: var(--font-hand);
  font-size: 17px;
  font-weight: 400;
}
.hero__meta span { font-size: 11px; color: var(--ink-3); letter-spacing: 0.08em; }

.budget { margin-top: 14px; }
.budget__top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--ink-2);
  margin-bottom: 5px;
}
.budget__top b { font-family: var(--font-hand); font-size: 15px; font-weight: 400; color: var(--ink); }
.budget__bar {
  position: relative;
  height: 15px;
  border: 2px solid var(--ink);
  border-radius: 9px 11px 8px 12px;
  background: var(--paper-2);
  overflow: hidden;
}
.budget__bar i {
  display: block;
  height: 100%;
  border-radius: 6px;
  background: repeating-linear-gradient(135deg, var(--green) 0 7px, rgba(47, 174, 132, 0.62) 7px 13px);
  transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.budget--over .budget__bar i {
  background: repeating-linear-gradient(135deg, var(--red) 0 7px, rgba(232, 86, 63, 0.6) 7px 13px);
}
.budget__link {
  font-family: var(--font-hand);
  font-size: 14px;
  color: var(--blue);
  border-bottom: 1.5px dashed currentColor;
}

/* 空状态 */
.empty {  text-align: center;
  padding: 26px 18px 24px;
  color: var(--ink-2);
  position: relative;
}
.empty__doodle { width: 118px; height: 96px; margin: 0 auto 6px; display: block; opacity: 0.9; }
.empty__title { font-family: var(--font-hand); font-size: 19px; color: var(--ink); }
.empty__text { font-size: 13px; margin-top: 6px; line-height: 1.6; color: var(--ink-3); }

/* 独立窗口提醒 */
.card.notice {
  background: rgba(239, 192, 59, 0.18);
  padding: 13px 14px;
  margin-bottom: 14px;
}
.notice__title { font-family: var(--font-hand); font-size: 16px; }
.notice__text { font-size: 12px; line-height: 1.7; color: var(--ink-2); margin-top: 5px; }
.notice .btn { margin-top: 10px; }

/* ---------- 6. 流水列表 ---------- */
.daygroup { margin-bottom: 14px; }

.daygroup__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 6px 8px;
  font-family: var(--font-hand);
  font-size: 15px;
  color: var(--ink-2);
  letter-spacing: 0.03em;
}
.daygroup__head .sum { font-size: 14px; color: var(--ink-3); }

.rows {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  position: relative;
}
.rows::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid var(--line-strong);
  border-radius: inherit;
  filter: url(#wobble-soft);
  pointer-events: none;
  opacity: 0.55;
}

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  position: relative;
  transition: background 0.15s ease;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 14px;
  right: 14px;
  height: 1.6px;
  background: repeating-linear-gradient(90deg, var(--line) 0 5px, transparent 5px 9px);
}
.row:active { background: rgba(239, 192, 59, 0.16); }

.sticker {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 19px;
  line-height: 1;
  border-radius: 13px 11px 14px 10px;
  background: var(--card);
  background: color-mix(in srgb, var(--c, #999) 22%, var(--card));
  border: 1.8px solid color-mix(in srgb, var(--c, #999) 62%, var(--ink));
  transform: rotate(-2.5deg);
}
.row:nth-child(even) .sticker { transform: rotate(2deg); }

.row__main { flex: 1; min-width: 0; }
.row__title {
  font-size: 15px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row__cat {
  font-size: 11px;
  color: var(--ink-3);
  margin-left: 6px;
  font-weight: 400;
}
.row__note {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row__amount {
  font-family: var(--font-hand);
  font-size: 19px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.row__amount.is-income { color: var(--green); }

/* ---------- 7. 统计页 ---------- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}
.stat-card {
  background: var(--card);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  padding: 11px 10px 10px;
  position: relative;
  text-align: center;
}
.stat-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border: 1.9px solid var(--line-strong);
  border-radius: inherit;
  filter: url(#wobble-soft);
  pointer-events: none;
  opacity: 0.6;
}
.stat-card b {
  display: block;
  font-family: var(--font-hand);
  font-size: 21px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}
.stat-card span { font-size: 11px; color: var(--ink-3); letter-spacing: 0.06em; }

.catbar { padding: 8px 0; }
.catbar__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 5px;
}
.catbar__name { display: flex; align-items: center; gap: 6px; }
.catbar__pct { font-family: var(--font-hand); font-size: 13px; color: var(--ink-3); }
.catbar__track {
  height: 13px;
  border: 1.8px solid var(--ink);
  border-radius: 7px 9px 6px 10px;
  background: var(--paper-2);
  overflow: hidden;
}
.catbar__fill {
  height: 100%;
  background: var(--c);
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.weekchart {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  height: 132px;
  padding-top: 14px;
}
.weekchart__col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 5px; }
.weekchart__val { font-family: var(--font-hand); font-size: 10px; color: var(--ink-3); white-space: nowrap; }
.weekchart__bar {
  width: 100%;
  max-width: 30px;
  border: 1.8px solid var(--ink);
  border-bottom: 0;
  border-radius: 6px 8px 0 0;
  background: var(--blue);
  min-height: 3px;
  transition: height 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.weekchart__day { font-size: 10px; color: var(--ink-3); }

.insight { display: flex; flex-direction: column; gap: 10px; }
.insight__row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.insight__row span { color: var(--ink-2); }
.insight__row b { font-family: var(--font-hand); font-size: 16px; font-weight: 400; text-align: right; }

/* ---------- 8. 设置页 ---------- */
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 2px;
  border-bottom: 1.6px dashed var(--line);
}
.setting:last-child { border-bottom: 0; }
.setting__label { font-size: 14px; }
.setting__label small { display: block; font-size: 11px; color: var(--ink-3); margin-top: 3px; line-height: 1.5; }
.setting__value { font-family: var(--font-hand); font-size: 16px; color: var(--ink-2); }

.input {
  font-family: var(--font-body);
  font-size: 16px;
  padding: 7px 9px;
  border-bottom: 2px dashed var(--line-strong);
  background: rgba(239, 192, 59, 0.08);
  min-width: 0;
  width: 100%;
}
.input:focus { background: rgba(239, 192, 59, 0.2); border-bottom-color: var(--ink); }
.input--sm { font-size: 15px; padding: 5px 7px; }

.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 3px;
  border: 2px solid var(--line-strong);
  border-radius: 12px 14px 11px 15px;
  background: var(--paper-2);
}
.segmented button {
  font-family: var(--font-hand);
  font-size: 14px;
  padding: 5px 10px;
  border-radius: 9px;
  color: var(--ink-2);
}
.segmented button.is-on { background: var(--card); color: var(--ink); box-shadow: 0 2px 0 var(--line-strong); }

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  border: 2px solid var(--ink);
  border-radius: 15px;
  background: var(--paper-2);
  flex: 0 0 auto;
  transition: background 0.2s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.switch.is-on { background: rgba(47, 174, 132, 0.35); }
.switch.is-on::after { transform: translateX(20px); }

.help {
  font-size: 12px;
  line-height: 1.7;
  color: var(--ink-2);
  background: rgba(74, 144, 217, 0.08);
  border: 1.6px dashed rgba(74, 144, 217, 0.5);
  border-radius: 12px;
  padding: 10px 12px;
  margin-top: 10px;
}
.help code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: rgba(51, 46, 40, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
  word-break: break-all;
}

.doc {
  font-size: 13.5px;
  line-height: 1.8;
  color: var(--ink-2);
  margin: 7px 2px 0;
}
.doc b { color: var(--ink); font-weight: 600; }
.doc code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: rgba(51, 46, 40, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
  word-break: break-all;
}
.doc-list {
  margin: 8px 0 0;
  padding-left: 20px;
  font-size: 13.5px;
  line-height: 1.9;
  color: var(--ink-2);
}
.doc-list li { list-style: decimal; }
.doc-list b { color: var(--ink); font-weight: 600; }

/* ---------- 9. 浮动按钮 / 标签栏 ---------- */
.fab {
  position: fixed;
  right: max(16px, calc((100vw - 520px) / 2 + 16px));
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 52px;
  padding: 0 20px 0 15px;
  font-family: var(--font-hand);
  font-size: 19px;
  color: #FFF9EE;
  background: var(--red);
  border: 2.4px solid var(--ink);
  border-radius: 26px 22px 28px 20px / 22px 28px 20px 26px;
  box-shadow: 4px 5px 0 rgba(51, 46, 40, 0.24);
  transform: rotate(-1.5deg);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.fab:active { transform: rotate(-1.5deg) translateY(4px); box-shadow: none; }
.fab svg { width: 20px; height: 20px; }

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  box-shadow: 0 -3px 14px rgba(51, 46, 40, 0.08);
}
.tabbar::before {
  content: "";
  position: absolute;
  top: -2px;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--ink);
  filter: url(#wobble);
  opacity: 0.85;
}
.tabbar__inner {
  display: flex;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
  color: var(--ink-3);
  font-size: 11px;
  letter-spacing: 0.06em;
  transition: color 0.18s ease;
}
.tab svg { width: 23px; height: 23px; }
.tab.is-active { color: var(--ink); }
.tab.is-active::before {
  content: "";
  position: absolute;
  top: 8px;
  width: 46px;
  height: 22px;
  background: rgba(239, 192, 59, 0.5);
  border-radius: 50% 46% 52% 48%;
  transform: rotate(-4deg);
  z-index: -1;
  animation: blobIn 0.3s ease both;
}
@keyframes blobIn {
  from { transform: rotate(-4deg) scale(0.6); opacity: 0; }
  to { transform: rotate(-4deg) scale(1); opacity: 1; }
}

/* ---------- 10. 弹层 / 记账器 ---------- */
.sheet-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-layer[hidden] { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(38, 32, 24, 0.44);
  opacity: 0;
  transition: opacity 0.26s ease;
}
.sheet-layer.is-in .sheet-backdrop { opacity: 1; }

.sheet {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: 94dvh;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-top: 2.6px solid var(--ink);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -8px 30px rgba(30, 24, 18, 0.24);
  transform: translateY(101%);
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.24, 1);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-layer.is-in .sheet { transform: none; }

.sheet__grab {
  width: 44px;
  height: 5px;
  border-radius: 3px;
  background: var(--line-strong);
  margin: 8px auto 0;
  opacity: 0.6;
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 4px;
}
.sheet__title { font-family: var(--font-hand); font-size: 20px; letter-spacing: 0.02em; }

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 4px 16px 8px;
  overscroll-behavior: contain;
}

.sheet__foot {
  display: flex;
  gap: 10px;
  padding: 10px 16px 12px;
  border-top: 2px dashed var(--line);
  background: var(--card);
}
.sheet__foot .btn { flex: 1; }

/* 支出/收入 */
.type-switch {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--paper-2);
  border: 2px solid var(--line-strong);
  border-radius: 14px;
  margin: 6px 0 10px;
}
.type-switch button {
  flex: 1;
  height: 34px;
  font-family: var(--font-hand);
  font-size: 16px;
  border-radius: 10px;
  color: var(--ink-2);
}
.type-switch button.is-on {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 0 var(--line-strong);
}

/* 金额 */
.amount-display {
  display: flex;
  align-items: baseline;
  gap: 2px;
  padding: 2px 2px 7px;
  margin-bottom: 2px;
  font-family: var(--font-hand);
  font-variant-numeric: tabular-nums;
  border-bottom: 2.4px dashed var(--line-strong);
}
.amount-display .cur { font-size: 24px; opacity: 0.55; }
.amount-display .num {
  font-size: 46px;
  line-height: 1.05;
  letter-spacing: 0.01em;
  min-width: 60px;
  display: inline-block;
}
.amount-display .num.is-empty { opacity: 0.32; }
.amount-display.is-income .num { color: var(--green); }
.amount-display .caret {
  width: 2.4px;
  height: 34px;
  background: var(--ink);
  margin-left: 2px;
  animation: blink 1.1s steps(1) infinite;
  align-self: center;
  opacity: 0.5;
}
@keyframes blink { 50% { opacity: 0; } }

/* 分类贴纸 */
.cat-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 2px 12px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(90deg, #000 0, #000 90%, transparent 100%);
  mask-image: linear-gradient(90deg, #000 0, #000 90%, transparent 100%);
}
.cat-strip::-webkit-scrollbar { display: none; }

.cat {
  flex: 0 0 auto;
  width: 62px;
  padding: 8px 2px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border-radius: 14px 11px 15px 10px;
  border: 2px solid transparent;
  transition: transform 0.14s ease, background 0.14s ease;
}
.cat .emoji { font-size: 23px; line-height: 1; }
.cat .name { font-family: var(--font-hand); font-size: 13px; color: var(--ink-2); }
.cat:active { transform: scale(0.94); }
.cat.is-on {
  background: var(--paper-2);
  background: color-mix(in srgb, var(--c) 24%, var(--card));
  border-color: var(--ink);
  transform: rotate(-2deg) scale(1.04);
}
.cat.is-on .name { color: var(--ink); }

/* 表单 */
.field { display: block; margin-top: 4px; }
.field__label {
  display: block;
  font-size: 11px;
  color: var(--ink-3);
  letter-spacing: 0.1em;
  margin-bottom: 2px;
}
.field + .field { margin-top: 10px; }

.datechips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.datechips input[type="date"] {
  font-family: var(--font-body);
  font-size: 15px;
  padding: 4px 6px;
  border-bottom: 2px dashed var(--line-strong);
  background: transparent;
  color: var(--ink);
  min-width: 128px;
}

/* 键区 */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  padding: 10px 16px 0;
}
.key {
  height: 50px;
  font-family: var(--font-hand);
  font-size: 24px;
  color: var(--ink);
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 12px 14px 11px 15px / 14px 11px 15px 12px;
  box-shadow: 0 3px 0 var(--line-strong);
  display: grid;
  place-items: center;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.key:active { transform: translateY(3px); box-shadow: none; background: var(--paper-2); }
.key[data-k="del"] { font-size: 20px; }

/* 识别结果面板 */
.recog {
  border: 2px dashed rgba(74, 144, 217, 0.6);
  background: rgba(74, 144, 217, 0.07);
  border-radius: 14px;
  padding: 9px 11px 8px;
  margin: 4px 0 8px;
}
.recog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-hand);
  font-size: 15px;
}
.recog__conf {
  font-size: 11px;
  color: var(--ink-2);
  font-family: var(--font-body);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.recog__hits { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.recog__hit {
  font-size: 10.5px;
  color: var(--ink-2);
  background: var(--card);
  border: 1.4px solid var(--line-strong);
  border-radius: 7px;
  padding: 2px 6px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.recog__more {
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--blue);
  border-bottom: 1px dashed currentColor;
  padding-bottom: 1px;
}
.recog__raw {
  margin-top: 7px;
  font-size: 10.5px;
  color: var(--ink-3);
  max-height: 90px;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.55;
  border-top: 1px dashed var(--line);
  padding-top: 6px;
}
.recog__raw[hidden] { display: none; }

/* 提示条 */
.toast-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + 84px + env(safe-area-inset-bottom));
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  transition: bottom 0.2s ease;
}
body.sheet-open .toast-wrap {
  bottom: auto;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
}
.toast {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 88vw;
  padding: 9px 14px;
  font-family: var(--font-hand);
  font-size: 16px;
  color: var(--paper);
  background: var(--ink);
  border-radius: 12px 14px 11px 15px;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.18);
  animation: toastIn 0.24s cubic-bezier(0.2, 0.9, 0.2, 1) both;
  pointer-events: auto;
}
.toast button {
  font-family: var(--font-hand);
  font-size: 15px;
  color: var(--yellow);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.toast.is-out { animation: toastOut 0.2s ease both; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) rotate(-2deg) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(-6px) scale(0.98); }
}

/* 保存时的盖章动画 */
@keyframes stamp {
  0% { transform: scale(0.86) rotate(-6deg); }
  55% { transform: scale(1.05) rotate(2deg); }
  100% { transform: scale(1) rotate(-1.5deg); }
}

/* ---------- 11. 响应式 / 无障碍 ---------- */
@media (max-width: 360px) {
  .hero__amount { font-size: 42px; }
  .row__amount { font-size: 17px; }
  .cat { width: 56px; }
}

/* 矮屏（iPhone SE 之类）把记账面板压紧，尽量不用滚动就能看到保存 */
@media (max-height: 720px) {
  .key { height: 44px; font-size: 22px; }
  .keypad { gap: 6px; padding-top: 8px; }
  .amount-display { padding-bottom: 5px; }
  .amount-display .num { font-size: 40px; }
  .amount-display .caret { height: 30px; }
  .cat { width: 56px; padding: 6px 2px 5px; }
  .cat .emoji { font-size: 21px; }
  .cat .name { font-size: 12px; }
  .cat-strip { padding: 6px 2px 8px; }
  .type-switch { margin: 2px 0 6px; }
  .type-switch button { height: 32px; }
  .field + .field { margin-top: 6px; }
  .datechips { margin-top: 6px; }
  .sheet__foot { padding: 8px 16px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --paper: #1F1B18;
    --paper-2: #262119;
    --card: #2A2521;
    --card-2: #332C25;
    --ink: #F6EDDD;
    --ink-2: #C4B8A4;
    --ink-3: #8E8474;
    --line: rgba(246, 237, 221, 0.14);
    --line-strong: rgba(246, 237, 221, 0.42);
    --red: #F0715C;
    --orange: #F2A64F;
    --yellow: #F3CB57;
    --green: #3FC79A;
    --blue: #6BA6E4;
    --purple: #A491E6;
    --pink: #EC7E9E;
    --shadow-sm: 2px 3px 0 rgba(0, 0, 0, 0.35);
    --shadow: 3px 5px 0 rgba(0, 0, 0, 0.38);
    --shadow-lg: 5px 7px 0 rgba(0, 0, 0, 0.42);
  }
}
