:root {
  color-scheme: light;
  --pink: #F0578E;
  --pink-soft: #FDE8F0;
  --bg: #FFF7FA;
  --card: #FFFFFF;
  --line: #F3E2E8;
  --text: #3D2A33;
  --muted: #8A6E78;
  --hint: #B9A2AB;
  --warn: #F5B942;
  --over: #E5484D;
  --c-joint: #F0578E;
  --c-me: #6C8AF0;
  --c-spouse: #FF9E6D;
  --c-home: #5DB894;
  --radius: 20px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* 关键：自定义 display 的元素会盖掉 UA 的 [hidden]，必须显式兜底 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

.view {
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 8px 4px 14px;
}
.topbar-month-line { display: flex; align-items: center; gap: 7px; }
.topbar-month { font-size: 13px; color: var(--muted); }
.who-badge {
  border: 0;
  border-radius: 999px;
  padding: 2.5px 9px 2.5px;
  font-family: inherit;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.4;
  color: #fff;
  background: var(--c-me);
  cursor: pointer;
}
.who-badge[data-who="spouse"] { background: var(--c-spouse); color: #8A4A1F; }
.who-badge:active { opacity: 0.75; }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 8px; }
.total-left {
  font-size: 30px;
  font-weight: 500;
  letter-spacing: -0.6px;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.sync-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 0;
  color: var(--hint);
  font-size: 11px;
  padding: 6px 4px;
  font-variant-numeric: tabular-nums;
}
.sync-btn.spin svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 赛跑卡 ---------- */
.accounts { display: flex; flex-direction: column; gap: 10px; }

.race {
  background: var(--card);
  border: 0.5px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px 12px;
  transition: border-color 0.2s ease;
}
.race[data-state="warn"] { border: 1px solid var(--warn); }
.race[data-state="over"] { border: 1px solid var(--over); }

.race-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 13px;
}
.race-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 500;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.race-left {
  font-size: 15px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.race[data-state="over"] .race-left { color: var(--over); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 500;
  color: #fff;
  background: var(--warn);
}
.race[data-state="over"] .badge { background: var(--over); }

/* 跑道 */
.track {
  position: relative;
  height: 10px;
  border-radius: 5px;
  background: #F6DCE7;
  margin-bottom: 9px;
}
.fill {
  height: 10px;
  border-radius: 5px;
  width: 0;
  transition: width 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}
.runner {
  position: absolute;
  top: -6px;
  width: 22px;
  height: 22px;
  transition: left 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  filter: drop-shadow(0 1px 2px rgba(61, 42, 51, 0.12));
}
.runner.shake { animation: shake 0.25s ease-in-out 2; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(3px); }
}

.race-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.race-foot .over-text { color: var(--over); }
.race-foot .warn-text { color: #BA7517; }
.race-foot .rollover-note { color: var(--hint); font-size: 11px; }

/* ---------- 储蓄卡 ---------- */
.savings-card {
  background: var(--card);
  border: 0.5px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin-top: 14px;
}
.savings-label { font-size: 12px; color: var(--muted); }
.savings-value {
  font-size: 25px;
  font-weight: 500;
  color: var(--pink);
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.savings-sub { font-size: 11px; color: var(--hint); margin-top: 3px; font-variant-numeric: tabular-nums; }

/* ---------- 底部按钮 ---------- */
.bottom-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, rgba(255, 247, 250, 0), var(--bg) 32%);
  max-width: 520px;
  margin: 0 auto;
}
.action-btn {
  flex: 1;
  height: 56px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.action-btn:active { transform: scale(0.97); }
.action-sign { font-size: 19px; font-weight: 500; line-height: 1; }
.action-text { font-size: 11px; }
.action-in { background: var(--card); border: 1px solid var(--pink); color: var(--pink); }
.action-out { background: var(--pink); border: 1px solid var(--pink); color: #fff; }

/* ---------- 记账页 ---------- */
.entry-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0 12px;
}
.back-btn {
  background: transparent;
  border: 0;
  padding: 6px;
  color: var(--text);
  display: flex;
}
.entry-title { font-size: 14px; font-weight: 500; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--card);
  border: 0.5px solid var(--line);
  border-radius: 16px;
  padding: 4px;
  margin-bottom: 14px;
}
.tab {
  flex: 1;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.tab[data-account="joint"].on { background: var(--c-joint); color: #fff; font-weight: 500; }
.tab[data-account="me"].on { background: var(--c-me); color: #fff; font-weight: 500; }
.tab[data-account="spouse"].on { background: var(--c-spouse); color: #fff; font-weight: 500; }
.tab[data-account="home"].on { background: var(--c-home); color: #fff; font-weight: 500; }
.tab[data-kind].on { background: var(--pink); color: #fff; font-weight: 500; }

.amount-row { display: flex; gap: 10px; margin-bottom: 18px; }
.amount-box {
  flex: 1;
  height: 64px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 14px;
  background: var(--card);
  border: 0.5px solid var(--line);
  border-radius: 16px;
}
.amount-yen { font-size: 20px; color: var(--muted); }
#amount {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font-family: inherit;
  font-size: 27px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
#amount::placeholder { color: var(--hint); }

.mic-btn {
  width: 82px;
  height: 64px;
  border: 0;
  border-radius: 16px;
  background: var(--pink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
  touch-action: none;
}
.mic-btn:active, .mic-btn.holding { transform: scale(0.97); background: #D9457C; }

.field { margin-bottom: 16px; }
.field-label { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 8px 15px;
  border-radius: 11px;
  border: 0.5px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip.on { background: var(--pink-soft); border-color: var(--pink); color: var(--pink); }
.chip-sep {
  width: 1px;
  height: 20px;
  background: var(--line);
  align-self: center;
  margin: 0 2px;
}

.note-input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 0.5px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: 0;
}
.note-input::placeholder { color: var(--hint); }

.voice-hint {
  font-size: 12px;
  color: var(--muted);
  background: var(--pink-soft);
  border-radius: 11px;
  padding: 9px 12px;
  margin-bottom: 14px;
}

.btn-save {
  width: 100%;
  height: 54px;
  border: 0;
  border-radius: 16px;
  background: var(--pink);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.15s ease, transform 0.12s ease;
}
.btn-save:active { transform: scale(0.99); }
.btn-save:disabled { opacity: 0.45; }

/* ---------- 明细页 ---------- */
.detail-summary {
  background: var(--card);
  border: 0.5px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}
.detail-summary .row {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 0;
  font-variant-numeric: tabular-nums;
}
.detail-summary .row b { color: var(--text); font-weight: 500; }
.detail-note { font-size: 11px; color: var(--hint); margin-top: 8px; }

.detail-list { display: flex; flex-direction: column; gap: 8px; }
.item {
  background: var(--card);
  border: 0.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.item-main { min-width: 0; }
.item-cat { font-size: 13px; font-weight: 500; }
.item-note {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item-amount {
  font-size: 14px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.item-amount.reverted { color: var(--hint); text-decoration: line-through; }
.empty { text-align: center; color: var(--hint); font-size: 13px; padding: 40px 0; }

/* ---------- 口令闸门 ---------- */
.gate {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 40;
}
.gate-inner { width: 100%; max-width: 300px; text-align: center; }
.gate-mark { margin-bottom: 14px; }
.gate h1 { font-size: 17px; font-weight: 500; margin: 0 0 6px; }
.muted { font-size: 12px; color: var(--muted); margin: 0 0 20px; }
#gate-input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 0.5px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  font-family: inherit;
  font-size: 15px;
  text-align: center;
  outline: 0;
  margin-bottom: 12px;
}
.btn-primary {
  width: 100%;
  height: 50px;
  border: 0;
  border-radius: 14px;
  background: var(--pink);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
}
.err { color: var(--over); font-size: 12px; margin-top: 10px; }

/* ---------- 语音遮罩 ---------- */
.mic-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 247, 250, 0.94);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 50;
}
.wave { display: flex; align-items: center; gap: 6px; height: 56px; }
.wave i {
  display: block;
  width: 7px;
  height: 10px;
  border-radius: 4px;
  background: var(--pink);
  animation: pulse 0.9s ease-in-out infinite;
}
.wave i:nth-child(1) { animation-delay: 0s; }
.wave i:nth-child(2) { animation-delay: 0.1s; }
.wave i:nth-child(3) { animation-delay: 0.2s; }
.wave i:nth-child(4) { animation-delay: 0.3s; }
.wave i:nth-child(5) { animation-delay: 0.4s; }
@keyframes pulse {
  0%, 100% { height: 10px; opacity: 0.5; }
  50% { height: 44px; opacity: 1; }
}
.mic-state { font-size: 15px; font-weight: 500; }
.mic-tip { font-size: 12px; color: var(--muted); }
.mic-overlay.cancel .mic-state { color: var(--over); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(61, 42, 51, 0.94);
  color: #fff;
  font-size: 13px;
  padding: 10px 18px;
  border-radius: 12px;
  z-index: 60;
  max-width: 82vw;
  text-align: center;
  animation: rise 0.2s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translate(-50%, 6px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

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