:root {
  color-scheme: light;
  --paper: #f3efe7;
  --paper-deep: #e7e1d6;
  --ink: #1c1917;
  --muted: #78716c;
  --line: #e4ddd2;
  --card: #fffdfb;
  --up: #0f6e56;
  --down: #9f2d2d;
  --shadow: 0 1px 0 rgba(28, 25, 23, 0.04), 0 10px 28px rgba(28, 25, 23, 0.05);
  --ubs: #1d4e89;
  --ahorro: #0f6e56;
  --piket: #b4532a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Color Emoji", sans-serif;
  color: var(--ink);
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
}

button, a, label { touch-action: manipulation; }

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

button { cursor: pointer; }

#app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
  position: relative;
}

.noscript {
  max-width: 480px;
  margin: 24px auto;
  padding: 0 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.content {
  padding-bottom: calc(108px + var(--sab));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + var(--sat)) calc(16px + var(--sar)) 12px calc(16px + var(--sal));
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(16px);
}

.topbar-account {
  align-items: center;
}

.topbar-account .account-title {
  flex: 1;
  min-width: 0;
}

.wordmark {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.045em;
  line-height: 1;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.rate-hint,
.sub,
.help,
.count,
.original,
.goal-copy,
.profit-note {
  color: var(--muted);
}

.rate-hint,
.original,
.goal-copy,
.profit-note,
.help,
.count {
  font-size: 13px;
  line-height: 1.4;
}

.rate-hint { margin: 8px 0 0; }

h1, h2, h3, p { margin: 0; }

.account-title {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  color: var(--ink);
  text-decoration: none;
  background: transparent;
  border: 0;
  flex: 0 0 auto;
}

.icon-btn svg { display: block; }

.cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 16px 0;
}

.card {
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border-radius: 22px;
  padding: 14px 16px 14px;
  border: 1px solid rgba(28, 25, 23, 0.06);
  border-top: 4px solid var(--accent);
  box-shadow: var(--shadow);
}

.card-ubs { --accent: var(--ubs); }
.card-ahorro { --accent: var(--ahorro); }
.card-piket { --accent: var(--piket); }

.card-top,
.month-line,
.bar-label,
.transfer-sums,
.sheet-head,
.cat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card h2 {
  font-size: 16px;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.pill {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent, var(--ink));
  background: color-mix(in srgb, var(--accent, var(--ink)) 12%, white);
  border-radius: 999px;
  padding: 4px 8px;
}

.balance {
  margin-top: 10px;
  font-size: clamp(28px, 8vw, 34px);
  font-weight: 700;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  line-height: 1.05;
}

.hero .balance { font-size: clamp(36px, 10vw, 44px); }

.original { margin-top: 4px; }

.month-kicker {
  margin-top: 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.month-line {
  margin-top: 6px;
  font-size: 14px;
  color: var(--muted);
  flex-wrap: wrap;
}

.month-line b,
.transfer-sums b {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.profit-line {
  margin-top: 10px;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.profit-line strong,
.big {
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.goal-mini { margin-top: 12px; }

.goal-copy { margin-top: 6px; }

.track {
  height: 8px;
  border-radius: 99px;
  background: var(--paper-deep);
  overflow: hidden;
}

.fill {
  height: 100%;
  border-radius: 99px;
  background: var(--ahorro);
  width: 0;
}

.hero {
  margin: 0 16px;
  padding: 4px 2px 8px;
}

.goal-box,
.profit-box,
.panel {
  margin: 12px 16px 0;
  background: var(--card);
  border: 1px solid rgba(28, 25, 23, 0.06);
  border-radius: 22px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.goal-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 650;
}

.big {
  margin-top: 4px;
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.controls {
  padding: 16px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--paper-deep);
  border-radius: 14px;
}

.seg button {
  border: 0;
  background: transparent;
  border-radius: 10px;
  min-height: 40px;
  padding: 8px 4px;
  font-size: 14px;
  font-weight: 650;
  color: var(--ink);
}

.seg button[aria-pressed="true"] {
  background: white;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08);
}

.seg label {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

.seg label input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}

.seg label:has(input:checked) {
  background: white;
  box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08);
}

.period-nav {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 6px;
}

.period-nav strong {
  display: block;
  text-align: center;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.nav-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 0;
  background: white;
  font-size: 26px;
  line-height: 1;
  color: var(--ink);
}

.bars {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bar-label {
  font-size: 14px;
  margin-bottom: 5px;
}

.bar-label span:last-child {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
}

.bar-track {
  height: 8px;
  border-radius: 99px;
  background: var(--paper-deep);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--bar, var(--ubs));
}

.empty { color: var(--muted); padding: 8px 0 2px; }

.count { margin-top: 8px; }

.ledger { padding: 8px 88px 0 16px; }

.day {
  margin: 16px 4px 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-transform: lowercase;
}

.move {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 12px 2px;
  min-height: 58px;
}

.move-emoji {
  width: 36px;
  text-align: center;
  font-size: 22px;
  flex: 0 0 auto;
}

.move-mid {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.move-title { font-weight: 650; }

.move-note {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.move-amt {
  text-align: right;
  flex: 0 0 auto;
}

.move-amt strong,
.move-amt small {
  display: block;
  font-variant-numeric: tabular-nums;
}

.move-amt strong { font-size: 15px; }

.move-amt small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.tone-pos { color: var(--up); }
.tone-neg { color: var(--down); }
.tone-transfer { color: var(--ink); }
.tone-zero { color: var(--muted); }

.fab {
  position: fixed;
  z-index: 20;
  right: max(16px, calc(50vw - 240px + 16px));
  bottom: calc(16px + var(--sab));
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  display: grid;
  place-items: center;
  box-shadow: 0 10px 24px rgba(28, 25, 23, 0.28);
}

.fab svg { display: block; }

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(28, 25, 23, 0.42);
}

.sheet {
  position: fixed;
  z-index: 31;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(480px, 100%);
  max-height: min(92dvh, 100%);
  overflow: auto;
  background: var(--paper);
  border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(18px + var(--sab));
  box-shadow: 0 -12px 40px rgba(28, 25, 23, 0.18);
}

.handle {
  width: 40px;
  height: 4px;
  border-radius: 4px;
  background: #d6d0c6;
  margin: 6px auto 8px;
}

.sheet-title {
  font-size: 20px;
  letter-spacing: -0.03em;
}

.field { display: block; margin-top: 14px; }

.field > span,
.choice-legend,
.cat-group h3 {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

input[type="text"],
input[type="date"],
textarea,
.cat-row input {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
}

.amount-field input {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  padding: 10px 12px;
}

textarea { min-height: 72px; resize: vertical; }

.choices { display: flex; flex-direction: column; gap: 8px; }

.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 10px 12px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 14px;
}

.choice:has(input:checked) {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.choice input { width: 18px; height: 18px; accent-color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip { position: relative; }

.chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
  width: 100%;
  height: 100%;
}

.chip span,
.seg label span { pointer-events: none; }

.chip span {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 999px;
  background: white;
  border: 1px solid var(--line);
  font-size: 14px;
}

.chip:has(input:checked) span {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.preview {
  min-height: 1.3em;
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
}

.form-error {
  margin-top: 10px;
  color: var(--down);
  background: #fde8e8;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: white;
  font-weight: 700;
}

.btn.primary {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
  margin-top: 16px;
}

.btn.danger {
  background: transparent;
  color: var(--down);
  border-color: transparent;
}

.btn.slim { margin-top: 0; }

.linkish {
  color: var(--ink);
  font-weight: 700;
}

.section {
  padding: 18px 16px 8px;
}

.section h2 {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.rate-row,
.balance-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.rate-row input,
.balance-row input { flex: 1; }

.cat-group { margin-top: 16px; }

.cat-row {
  display: grid;
  grid-template-columns: 64px 1fr 44px;
  gap: 8px;
  margin-bottom: 8px;
}

.icon-x {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: white;
  color: var(--muted);
  font-size: 22px;
}

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(88px + var(--sab));
  max-width: min(420px, calc(100% - 32px));
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 14px;
  text-align: center;
  pointer-events: none;
}

body:has(.sheet) {
  overflow: hidden;
  overscroll-behavior: none;
}

body:has(.sheet) .fab { visibility: hidden; }

@media (min-width: 520px) {
  html, body { background: #e4ddd2; }
  #app { box-shadow: 0 0 0 1px rgba(28, 25, 23, 0.04); }
}

@media (hover: hover) {
  .card:hover { transform: translateY(-1px); }
  .icon-btn:hover,
  .nav-btn:hover,
  .icon-x:hover { background: white; }
}

.card:active,
.btn:active,
.seg button:active { transform: scale(0.985); }

.fab:active { transform: scale(0.96); }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
