:root {
  color-scheme: light;
  --bg: #f5f5fb;
  --card: rgba(255, 255, 255, 0.94);
  --text: #171629;
  --muted: #77758a;
  --primary: #5b4ff0;
  --primary-2: #8b5cf6;
  --line: #e9e8f1;
  --danger: #e5484d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--text);
  background:
    radial-gradient(circle at 90% -10%, rgba(139, 92, 246, 0.18), transparent 34%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { cursor: pointer; }

#app {
  width: min(100%, 680px);
  margin: 0 auto;
  padding-bottom: calc(94px + var(--safe-bottom));
}

.page {
  display: none;
  padding: max(22px, env(safe-area-inset-top)) 16px 24px;
  animation: page-in 180ms ease-out;
}

.page.active { display: block; }

@keyframes page-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 4px 22px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

h1 { margin: 0; font-size: 32px; letter-spacing: -0.04em; }
h2 { margin: 0 0 13px; font-size: 17px; }

.brand-mark, .icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 16px;
  color: white;
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 24px rgba(91, 79, 240, 0.25);
}
.record-actions { display: flex; gap: 8px; }
.icon-button.secondary { color: var(--primary); background: rgba(91,79,240,.11); box-shadow: none; cursor: pointer; }
.backup-hint { margin: -14px 4px 14px; color: var(--muted); font-size: 12px; text-align: right; }

.card {
  margin-bottom: 15px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 8px 26px rgba(38, 35, 70, 0.055);
  backdrop-filter: blur(20px);
}

.amount-card label, .field-label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.amount-input {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.amount-input span { font-size: 30px; font-weight: 750; }

.amount-input input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: clamp(40px, 13vw, 58px);
  font-weight: 800;
  letter-spacing: -0.055em;
}

.amount-input input::placeholder { color: #d0cfda; }

.category {
  border: 0;
  border-radius: 14px;
  color: var(--text);
  background: #f2f1f7;
  font-weight: 700;
}
.category.active { color: white; background: var(--primary); box-shadow: 0 8px 16px rgba(91, 79, 240, 0.2); }

.category-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.category { display: flex; flex-direction: column; align-items: center; gap: 7px; padding: 12px 6px; font-size: 13px; }
.category span { font-size: 22px; line-height: 1; }

#note {
  width: 100%;
  padding: 13px;
  border: 0;
  border-radius: 13px;
  outline: none;
  background: #f2f1f7;
}

.primary-button {
  width: 100%;
  padding: 17px;
  border: 0;
  border-radius: 17px;
  color: white;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 12px 25px rgba(91, 79, 240, 0.28);
  font-size: 17px;
  font-weight: 800;
}

.tab-bar {
  position: fixed;
  z-index: 20;
  right: 12px;
  bottom: calc(10px + var(--safe-bottom));
  left: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: min(calc(100% - 24px), 640px);
  margin: auto;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.85);
  border-radius: 22px;
  background: rgba(255,255,255,.9);
  box-shadow: 0 15px 38px rgba(26, 23, 51, .16);
  backdrop-filter: blur(24px);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px;
  border: 0;
  border-radius: 15px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 700;
}
.tab span { font-size: 21px; line-height: 1; }
.tab.active { color: var(--primary); background: rgba(91, 79, 240, .09); }

.summary-strip {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  color: #554f6d;
  background: rgba(255,255,255,.7);
  font-size: 13px;
}

.records-list { display: grid; gap: 10px; }
.record-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 15px;
  border-radius: 18px;
  background: white;
  box-shadow: 0 7px 20px rgba(38,35,70,.045);
}
.record-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: #eeecff; font-size: 21px; }
.record-copy { min-width: 0; flex: 1; }
.record-copy strong, .record-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-copy small { margin-top: 5px; color: var(--muted); }
.record-amount { font-weight: 800; font-variant-numeric: tabular-nums; }
.delete-button { padding: 7px; border: 0; color: #aaa6b5; background: transparent; font-size: 17px; }
.empty-state { padding: 70px 24px; text-align: center; color: var(--muted); }
.empty-state span { display: block; margin-bottom: 12px; font-size: 48px; }

.month-nav { display: flex; align-items: center; gap: 5px; }
.month-nav button { display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 11px; color: var(--primary); background: rgba(91,79,240,.1); font-size: 24px; line-height: 1; }
.month-nav button:disabled { opacity: .3; }
.month-chip { min-width: 92px; padding: 9px 10px; border-radius: 12px; color: var(--primary); background: rgba(91,79,240,.1); font-size: 13px; font-weight: 800; text-align: center; }
.total-card { display: flex; flex-direction: column; gap: 8px; margin-bottom: 15px; padding: 23px; border-radius: 24px; color: white; background: linear-gradient(135deg, var(--primary), #995ff2); box-shadow: 0 14px 28px rgba(91,79,240,.25); }
.total-card p { margin: 0; opacity: .8; font-size: 14px; }
.total-card strong { font-size: 42px; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.total-card span { opacity: .75; font-size: 13px; }
.stats-list { display: grid; gap: 17px; }
.stat-row-head { display: flex; align-items: center; gap: 7px; margin-bottom: 8px; font-size: 14px; }
.stat-row-head strong { margin-left: auto; font-variant-numeric: tabular-nums; }
.stat-row-head small { width: 36px; color: var(--muted); text-align: right; }
.progress { height: 8px; overflow: hidden; border-radius: 999px; background: #ebeaf1; }
.progress > div { height: 100%; min-width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--primary-2)); transition: width .35s ease; }
.swipe-hint { margin: 18px 0 4px; color: var(--muted); font-size: 12px; text-align: center; }

.toast {
  position: fixed;
  z-index: 40;
  right: 20px;
  bottom: calc(100px + var(--safe-bottom));
  left: 20px;
  max-width: 440px;
  margin: auto;
  padding: 13px 17px;
  border-radius: 15px;
  color: white;
  background: rgba(28, 26, 44, .92);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: .2s ease;
  text-align: center;
  font-size: 14px;
}
.toast.show { opacity: 1; transform: translateY(0); }

dialog { width: min(calc(100% - 40px), 360px); padding: 22px; border: 0; border-radius: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.22); }
dialog::backdrop { background: rgba(15,13,25,.35); backdrop-filter: blur(3px); }
dialog h2 { margin-bottom: 7px; }
dialog p { color: var(--muted); }
.dialog-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 20px; }
.dialog-actions button { padding: 12px; border: 0; border-radius: 12px; background: #efeff5; font-weight: 750; }
.dialog-actions .danger { color: white; background: var(--danger); }

@media (min-width: 700px) {
  .page { padding-top: 34px; }
}
