:root {
    --bg: #F3F0EB;
    --card: #FFFCF8;
    --ink: #1C1916;
    --muted: #7A736C;
    --line: #E6DFD6;
    --accent: #C45E28;
    --accent-soft: #F8EBE3;
    --green: #1F6B4A;
    --green-soft: #E7F3EC;
    --danger: #B42318;
    --shadow: 0 1px 2px rgba(28,25,22,.04), 0 8px 24px rgba(28,25,22,.05);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bot: env(safe-area-inset-bottom, 0px);
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 16px; line-height: 1.4; }
  body { overscroll-behavior: none; }
  button, input { font: inherit; color: inherit; }
  button { border: 0; background: none; cursor: pointer; padding: 0; }
  input { border: 0; background: transparent; outline: none; width: 100%; }
  .app { min-height: 100%; display: flex; flex-direction: column; padding-top: var(--safe-top); }
  .topbar { display: flex; align-items: center; justify-content: space-between;
    padding: 8px 16px 0; min-height: 44px; gap: 8px; }
  .topbar .side { width: 72px; display: flex; align-items: center; }
  .topbar .side.right { justify-content: flex-end; }
  .home-topbar .side { width: 100px; gap: 4px; }
  .home-topbar .link-btn { min-width: 44px; min-height: 44px; white-space: nowrap; }
  #refresh-book { min-width: 3.2em; }
  #refresh-book:disabled { color: var(--muted); }
  .back { display: inline-flex; align-items: center; gap: 2px; color: var(--accent);
    font-size: 16px; font-weight: 500; padding: 8px 4px 8px 0; }
  .back svg { width: 20px; height: 20px; }
  .topbar h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: .02em; text-align: center; flex: 1; }
  .link-btn { color: var(--accent); font-size: 15px; font-weight: 500; padding: 8px 0; }
  .link-btn.danger { color: var(--danger); }
  .page { flex: 1; padding: 8px 16px calc(96px + var(--safe-bot)); }
  .hero { padding: 8px 4px 20px; }
  .hero .label { font-size: 13px; color: var(--muted); font-weight: 500; }
  .hero .title { font-size: 32px; font-weight: 700; letter-spacing: -0.03em; margin: 2px 0 12px; }
  .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px;
    padding: 14px 16px; box-shadow: var(--shadow); }
  .stat .k { font-size: 12px; color: var(--muted); }
  .stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; margin-top: 4px; }
  .stat .v em { font-style: normal; font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 2px; }
  .banner { background: var(--accent-soft); color: #7A3514; border-radius: 12px;
    padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
  .section-label { font-size: 13px; color: var(--muted); font-weight: 600;
    padding: 8px 4px 8px; letter-spacing: .04em; }
  .list { background: var(--card); border: 1px solid var(--line); border-radius: 16px;
    overflow: hidden; box-shadow: var(--shadow); }
  .row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
    padding: 14px 14px; background: var(--card); color: inherit; border-bottom: 1px solid var(--line); }
  .list .row:last-child { border-bottom: 0; }
  .row:active { background: #F7F3EE; }
  .avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft);
    color: var(--accent); font-weight: 700; font-size: 15px; display: grid; place-items: center; flex-shrink: 0; }
  .row .meta { flex: 1; min-width: 0; }
  .row .name { font-size: 16px; font-weight: 600; }
  .row .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
  .row .right { text-align: right; flex-shrink: 0; }
  .row .kg { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
  .row .kg em { font-style: normal; font-size: 11px; font-weight: 600; color: var(--muted); margin-left: 1px; }
  .chev { width: 16px; height: 16px; color: #C4BDB4; flex-shrink: 0; }
  .rec { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; width: 100%;
    text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--card); color: inherit; }
  .list .rec:last-child { border-bottom: 0; }
  .rec:active { background: #F7F3EE; }
  .rec .date { font-size: 15px; font-weight: 600; }
  .rec .amt { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
  .rec .detail { font-size: 12px; color: var(--muted); grid-column: 1 / -1; font-variant-numeric: tabular-nums; }
  .empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: 14px; }
  .dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + var(--safe-bot));
    background: linear-gradient(to top, var(--bg) 70%, rgba(243,240,235,0)); }
  .btn { display: block; width: 100%; height: 50px; border-radius: 14px; font-size: 16px; font-weight: 650;
    background: var(--accent); color: #fff; }
  .btn:active { filter: brightness(.95); }
  .btn:disabled { opacity: .4; }
  .btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
  .form { background: var(--card); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); }
  .field { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .form .field:last-child { border-bottom: 0; }
  .field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; font-weight: 500; }
  .field input { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
  .field input::placeholder { color: #C8C1B8; font-weight: 500; }
  .field.hero-field input { font-size: 36px; font-weight: 750; letter-spacing: -0.04em; width: calc(100% - 2.2em); }
  .field.hero-field { position: relative; padding: 16px 16px 18px; background: var(--green-soft); }
  .field.hero-field label { color: var(--green); font-weight: 650; }
  .unit { position: absolute; right: 16px; bottom: 22px; font-size: 16px; font-weight: 650; color: var(--green); }
  .preview { margin-top: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 16px;
    padding: 14px 16px; display: flex; justify-content: space-between; align-items: baseline; box-shadow: var(--shadow); }
  .preview .k { font-size: 13px; color: var(--muted); }
  .preview .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
  .hint { font-size: 12px; color: var(--muted); padding: 10px 4px 0; }
  .sheet-actions { display: flex; gap: 8px; margin-top: 8px; }
  .sheet-actions .btn { flex: 1; }
  body.is-preview .app { padding-top: calc(var(--safe-top) + 54px); }

  /* ===== v2 theme ===== */
  :root {
    --bg: #F4F5FB; --card: #FFFFFF; --ink: #0F172A; --muted: #64748B; --line: #E8EAF3;
    --accent: #4F46E5; --accent-soft: #EEF0FF; --green: #4F46E5; --green-soft: #EEF0FF;
    --danger: #E11D48;
    --shadow: 0 1px 2px rgba(15,23,42,.04), 0 10px 30px rgba(79,70,229,.08);
  }
  html, body { background: var(--bg); }
  .topbar h1 { font-weight: 700; }
  .hero { background: linear-gradient(135deg, #1E1B4B 0%, #3730A3 55%, #6366F1 100%);
    color: #fff; border-radius: 24px; padding: 20px 18px 18px; margin: 4px 0 18px;
    box-shadow: 0 16px 40px rgba(55,48,163,.28); position: relative; overflow: hidden; }
  .hero::after { content: ""; position: absolute; right: -40px; top: -50px; width: 180px; height: 180px;
    border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,.18), rgba(255,255,255,0) 70%); }
  .hero .label { color: rgba(255,255,255,.72); }
  .hero .title { color: #fff; }
  .hero .title span { color: rgba(255,255,255,.6) !important; }
  .hero .stat { background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.16); box-shadow: none;
    backdrop-filter: blur(6px); }
  .hero .stat .k { color: rgba(255,255,255,.7); }
  .hero .stat .v { color: #fff; }
  .hero .stat .v em { color: rgba(255,255,255,.65); }
  .list { border-radius: 20px; border-color: var(--line); }
  .avatar { width: 44px; height: 44px; border-radius: 50%; color: #fff; font-size: 17px; font-weight: 700;
    box-shadow: 0 4px 12px rgba(15,23,42,.14), inset 0 0 0 2px rgba(255,255,255,.35); }
  .row .kg { color: var(--ink); }
  .rec .amt { color: var(--accent); }
  .btn { background: linear-gradient(135deg, #4F46E5, #7C3AED); border-radius: 16px;
    box-shadow: 0 10px 24px rgba(79,70,229,.32); }
  .dock { background: linear-gradient(to top, var(--bg) 70%, rgba(244,245,251,0)); }
  .field.hero-field { background: var(--accent-soft); }
  .field.hero-field label, .unit { color: var(--accent); }
  .preview .v { color: var(--accent); }
  .banner { background: #EEF0FF; color: #3730A3; }
  .back, .link-btn { color: var(--accent); }
  .p-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
  .p-head .avatar { width: 52px; height: 52px; font-size: 20px; }
  .hidden { display: none !important; }
.auth-field input { font-size: 20px; }
.auth-link { display: inline-flex; align-items: center; min-height: 44px; text-decoration: none; }
.auth-nav { display: flex; justify-content: space-between; gap: 12px; }
.error { color: var(--danger); font-size: 14px; padding: 8px 4px; overflow-wrap: anywhere; }
.error:empty, [hidden] { display: none !important; }
.code { display: block; font: 600 clamp(16px,4.5vw,22px) monospace; overflow-wrap: anywhere; user-select: all; }
.lookup { margin-bottom: 10px; }
.name,.topbar h1 { overflow-wrap: anywhere; }
.field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.waiting { padding: 16px; color: var(--muted); }
.summary-hero::after { pointer-events: none; }
.period-controls { position: relative; z-index: 1; margin-bottom: 16px; }
.period-tabs { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 2px; padding: 3px; border: 1px solid #ffffff30; background: #13103440; border-radius: 12px; }
.period-tabs button { color: #fff; min-height: 36px; font-size: 14px; border-radius: 9px; }
.period-tabs button[aria-pressed="true"] { background: #fff; color: #3730a3; font-weight: 700; }
.period-date { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 9px; color: #fff; font-size: 14px; }
.period-date input { color: var(--ink); background: #fff; padding: 6px 10px; border-radius: 9px; width: auto; max-width: 70%; min-height: 36px; font-size: 16px; }
.summary-hero .title { margin-bottom: 0; overflow-wrap: anywhere; }
.summary-hero .title span { font-size: 18px; }
.weight-meta { margin: 0 0 14px; font-size: 13px; color: #ffffffc9; }
.finance-stats { grid-template-columns: repeat(2,minmax(0,1fr)); }
.finance-stats .stat { text-align: left; padding: 12px; min-width: 0; }
.finance-stats .v { display: block; font-size: clamp(17px, 5vw, 22px); overflow-wrap: anywhere; }
.profit-line { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; border-top: 1px solid #ffffff40; padding-top: 10px; margin-top: 12px; }
.profit-line span { font-size: 14px; }
.profit-line strong { font-size: 23px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.dock-pair { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 10px; }
.btn.secondary { color: var(--accent); background: var(--card); border: 1px solid #d6d5f6; box-shadow: var(--shadow); }
.expense-row .date { overflow-wrap: anywhere; }
.ledger-choice { margin: 4px 0 12px; }
.ledger-choice select { width: 100%; min-height: 40px; font: inherit; font-weight: 600; border: 1px solid var(--line); border-radius: 9px; padding: 6px 9px; background: var(--card); color: var(--ink); }

.account-profile {
  display: grid;
  justify-items: center;
  gap: 5px;
  margin: 4px auto 15px;
  text-align: center;
}
.account-profile figcaption {
  max-width: 100%;
  color: #59576d;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.account-mascot { position: relative; display: block; width: 76px; height: 76px; }
.mascot-shadow {
  position: absolute; left: 20px; bottom: 0; width: 38px; height: 5px;
  border-radius: 50%; background: #29213b33; filter: blur(2px);
}
.mascot-hop { position: absolute; inset: 3px 4px 6px; transform-origin: 50% 98%; }
.mascot-body {
  position: absolute; inset: 0; overflow: hidden;
  border-radius: 52% 48% 45% 55% / 57% 51% 49% 43%;
  background: linear-gradient(145deg, #26232e, #0d0c12 68%);
}
.mascot-gaze {
  position: absolute; top: 20%; left: 47%;
  display: flex; gap: 6px; align-items: center;
  transform: rotate(-25deg);
}
.mascot-gaze i { display: block; width: 8px; height: 18px; border-radius: 70%; background: white; }
.mascot-gaze i + i { width: 7px; height: 15px; }
.mascot-star {
  position: absolute; right: -3px; bottom: -2px; display: grid; place-items: center;
  width: 23px; height: 23px; border: 3px solid var(--bg); border-radius: 50%; background: #ffa51b;
}
.mascot-star::before {
  content: ""; width: 11px; height: 11px; background: #fff;
  clip-path: polygon(50% 0, 65% 31%, 100% 38%, 75% 62%, 80% 98%, 50% 81%, 20% 98%, 25% 62%, 0 38%, 35% 31%);
}
@media (prefers-reduced-motion: no-preference) {
  .mascot-hop { animation: mascot-hop 3.2s ease-in-out infinite; }
  .mascot-shadow { animation: mascot-shadow 3.2s ease-in-out infinite; }
  .mascot-gaze { animation: mascot-look 5.6s ease-in-out infinite; }
  .mascot-gaze i { animation: mascot-blink 5.1s ease-in-out infinite; }
}
@keyframes mascot-hop {
  0%, 52%, 83%, 100% { transform: none; }
  58% { transform: scale(1.04,.95); }
  68% { transform: translateY(-6px) rotate(-4deg) scale(.98,1.02); }
  77% { transform: scale(1.035,.965); }
}
@keyframes mascot-shadow {
  0%, 58%, 78%, 100% { transform: none; opacity: 1; }
  68% { transform: scaleX(.75); opacity: .6; }
}
@keyframes mascot-look {
  0%, 16%, 87%, 100% { transform: translate(0,0) rotate(-25deg); }
  32%, 48% { transform: translate(-9px,3px) rotate(-12deg); }
  63%, 75% { transform: translate(-2px,-2px) rotate(-22deg); }
}
@keyframes mascot-blink {
  0%, 69%, 74%, 100% { transform: scaleY(1); }
  71.5% { transform: scaleY(.12); }
}
