:root {
  --bg: #fff6fb;
  --bg2: #f0e9ff;
  --card: #ffffff;
  --ink: #2b2140;
  --muted: #7a6f8f;
  --primary: #7c5cff;
  --primary-dark: #5f3dff;
  --success: #2ec27e;
  --success-dark: #1fa865;
  --danger: #ff5d7a;
  --danger-dark: #e64360;
  --warn: #ff9f43;
  --warn-dark: #e8891f;
  --shadow: 0 10px 30px rgba(80, 40, 140, 0.12);
  --radius: 22px;
  --font: "Segoe UI", "Nunito", system-ui, -apple-system, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0%, #ffe3f1 0%, transparent 45%),
    radial-gradient(circle at 90% 10%, #e4dcff 0%, transparent 40%),
    linear-gradient(180deg, var(--bg), var(--bg2));
}

body {
  padding: 16px 14px 40px;
}

.app {
  max-width: 480px;
  margin: 0 auto;
}

.header {
  text-align: center;
  margin-bottom: 18px;
}

.logo {
  font-size: 42px;
  line-height: 1;
  filter: drop-shadow(0 4px 8px rgba(124, 92, 255, 0.25));
}

.header h1 {
  margin: 6px 0 0;
  font-size: 1.55rem;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.balance-card {
  background: linear-gradient(135deg, #8b6bff 0%, #ff7ab8 100%);
  color: #fff;
  border-radius: 28px;
  padding: 28px 20px;
  text-align: center;
  box-shadow: 0 16px 36px rgba(124, 92, 255, 0.35);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.balance-card::after {
  content: "✨";
  position: absolute;
  right: 16px;
  top: 12px;
  font-size: 22px;
  opacity: 0.85;
}

.balance-label {
  font-size: 1rem;
  font-weight: 600;
  opacity: 0.92;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.balance-value {
  font-size: clamp(2.2rem, 10vw, 3rem);
  font-weight: 800;
  margin-top: 4px;
  letter-spacing: -0.03em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.balance-hint {
  margin-top: 10px;
  background: rgba(255, 255, 255, 0.22);
  display: inline-block;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 1.15rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.card-head h2 {
  margin: 0;
}

.empty {
  margin: 0;
  color: var(--muted);
  text-align: center;
  padding: 12px 6px;
  font-size: 0.95rem;
}

.piggy-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.piggy-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f7f3ff;
  border: 2px solid #e8deff;
  border-radius: 18px;
  padding: 12px;
}

.piggy-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.piggy-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.piggy-amount {
  font-weight: 800;
  color: var(--primary);
  white-space: nowrap;
}

.piggy-actions {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 6px;
}

.debt-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  background: #fff8ef;
  border-radius: 16px;
  margin-bottom: 10px;
  border: 2px solid #ffe6c7;
}

.debt-row:last-child {
  margin-bottom: 0;
}

.debt-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.debt-emoji {
  font-size: 1.8rem;
}

.debt-name {
  font-weight: 700;
}

.debt-amount {
  color: var(--warn-dark);
  font-weight: 800;
  font-size: 1.05rem;
}

.action {
  padding: 12px 0;
  border-top: 1px dashed #eadfff;
}

.action:first-of-type {
  border-top: none;
  padding-top: 0;
}

.action-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.action-hint {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.88rem;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

input[type="number"],
input[type="text"] {
  width: 100%;
  border: 2px solid #e0d5ff;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: #faf8ff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.18);
}

.btn {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 0.98rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: #fff;
  transition: transform 0.08s ease, filter 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-small {
  padding: 8px 12px;
  font-size: 0.88rem;
  border-radius: 12px;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: linear-gradient(180deg, var(--primary), var(--primary-dark));
}

.btn-success {
  background: linear-gradient(180deg, var(--success), var(--success-dark));
}

.btn-danger {
  background: linear-gradient(180deg, var(--danger), var(--danger-dark));
}

.btn-warn {
  background: linear-gradient(180deg, var(--warn), var(--warn-dark));
}

.btn-ghost {
  background: #efe9ff;
  color: var(--ink);
}

.btn-soft {
  background: #fff;
  color: var(--primary-dark);
  border: 2px solid #d9ccff;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.btn-soft-danger {
  background: #fff;
  color: var(--danger-dark);
  border: 2px solid #ffd0da;
  padding: 8px 10px;
  font-size: 0.85rem;
}

.footer {
  text-align: center;
  color: var(--muted);
  margin-top: 8px;
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(35, 20, 60, 0.45);
}

.modal-sheet {
  position: relative;
  width: min(100%, 420px);
  background: #fff;
  border-radius: 24px 24px 20px 20px;
  padding: 20px 18px 18px;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.18);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-sheet h3 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.modal-sub {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.modal-sheet input {
  margin-bottom: 14px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@media (min-width: 520px) {
  .modal {
    align-items: center;
  }
  .modal-sheet {
    border-radius: 24px;
  }
}

.field-label {
  display: block;
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 6px;
}

.modal-sheet .field-label + input {
  margin-bottom: 12px;
}

.piggy-goal {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 600;
}

.piggy-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.piggy-progress-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
}

.piggy-progress-label span:last-child {
  color: var(--primary-dark);
  white-space: nowrap;
}

.piggy-progress-bar {
  height: 12px;
  background: #e8deff;
  border-radius: 999px;
  overflow: hidden;
}

.piggy-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #8b6bff, #ff7ab8);
  border-radius: 999px;
  transition: width 0.25s ease;
  min-width: 0;
}
