@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Nunito:wght@500;600;700;800&display=swap');

:root {
  --primary: #E86A92;
  --secondary: #F2B8A2;
  --bg-top: #FFF1F4;
  --bg-bottom: #F9E4D4;
  --ink: #5A2236;
  --card: rgba(255, 255, 255, 0.72);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --tab-h: 72px;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  font-family: 'Nunito', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) fixed;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
body { padding-bottom: calc(var(--tab-h) + var(--safe-bottom)); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, select, textarea {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
}
a { color: inherit; }

#app { min-height: 100dvh; }
#confetti {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 40;
}
#banner-slot {
  position: fixed; top: calc(12px + var(--safe-top)); left: 16px; right: 16px;
  z-index: 30; pointer-events: none;
}
#banner-slot .banner { pointer-events: auto; }

.screen {
  padding: calc(16px + var(--safe-top)) 20px 28px;
  max-width: 560px;
  margin: 0 auto;
  animation: fade-in 0.35s ease;
}
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 26px;
  padding: 18px;
  box-shadow: 0 8px 28px rgba(183, 110, 121, 0.12);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.card + .card, .stack > * + * { margin-top: 14px; }
.stack { display: flex; flex-direction: column; gap: 14px; }

h1, .title {
  font-family: 'Nunito', system-ui, sans-serif;
  font-weight: 800;
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.15;
}
.serif { font-family: 'Fraunces', Georgia, serif; }
.muted { color: color-mix(in srgb, var(--ink) 60%, transparent); }
.tiny { font-size: 0.8rem; }
.caption { font-size: 0.85rem; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary); font-weight: 700; font-size: 0.85rem;
}
.money {
  font-size: clamp(2.4rem, 12vw, 3.4rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
}
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }

.btn-primary {
  display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 16px 22px; border-radius: 999px;
  color: #fff; font-weight: 800; font-size: 1.05rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 35%, transparent);
  transition: transform 0.15s ease;
}
.btn-primary:active { transform: scale(0.96); }
.btn-primary:disabled { opacity: 0.45; pointer-events: none; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  width: 54px; height: 54px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.8); font-size: 1.2rem;
}
.btn-text {
  color: color-mix(in srgb, var(--ink) 70%, transparent);
  font-weight: 600; font-size: 0.95rem; padding: 8px;
}
.nav-row { display: flex; gap: 12px; margin-top: 16px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 14px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
  font-weight: 600; font-size: 0.9rem;
}
.chip.on {
  color: #fff; border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}
.flow { display: flex; flex-wrap: wrap; gap: 8px; }

.progress {
  height: 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  overflow: hidden;
}
.progress > i {
  display: block; height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transition: width 0.4s ease;
}

.field {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
}
.field input { font-size: 1.15rem; font-weight: 700; }
.field.big input { font-size: 2rem; }
label.block { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.9rem; }
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0;
}
.toggle input {
  appearance: none; width: 48px; height: 28px; border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 18%, transparent); position: relative; flex: 0 0 auto;
}
.toggle input::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: #fff;
  transition: transform 0.2s ease;
}
.toggle input:checked { background: var(--primary); }
.toggle input:checked::after { transform: translateX(20px); }

.day-chip {
  flex: 1; aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 0.72rem; font-weight: 700;
  background: rgba(255, 255, 255, 0.8);
}
.day-chip.on {
  color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.machine {
  position: relative; width: 220px; height: 220px; margin: 8px auto;
  display: grid; place-items: center; cursor: pointer; user-select: none;
}
.machine .halo {
  position: absolute; inset: 15px; border-radius: 50%;
  background: radial-gradient(circle at center, #fff, color-mix(in srgb, var(--secondary) 45%, transparent));
  border: 2px solid color-mix(in srgb, var(--primary) 25%, transparent);
  box-shadow: 0 10px 28px color-mix(in srgb, var(--primary) 25%, transparent);
}
.machine .face {
  position: relative; z-index: 2; font-size: 92px; line-height: 1;
  animation: bob 2.2s ease-in-out infinite;
}
.machine.resting .face { animation: snooze 3.2s ease-in-out infinite; transform: rotate(-8deg); }
.machine .coin, .machine .zzz {
  position: absolute; z-index: 1; pointer-events: none;
}
.machine .coin { font-size: 26px; animation: fall 1.4s linear infinite; }
.machine .zzz {
  font-weight: 800; color: color-mix(in srgb, var(--primary) 70%, transparent);
  animation: zzz 2.8s ease-out infinite;
}
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes snooze { 0%, 100% { transform: rotate(-8deg) translateY(0); } 50% { transform: rotate(-8deg) translateY(2px); } }
@keyframes fall {
  0% { transform: translateY(-110px) scale(1); opacity: 1; }
  85% { opacity: 1; }
  100% { transform: translateY(-30px) scale(0.6); opacity: 0; }
}
@keyframes zzz {
  0% { transform: translate(50px, -40px) scale(0.7); opacity: 0.8; }
  100% { transform: translate(80px, -100px) scale(1.3); opacity: 0; }
}
.machine.bounce .face { animation: pop 0.35s ease; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.18); } 100% { transform: scale(1); } }

.tap-bubble {
  position: absolute; top: -8px; left: 50%; transform: translateX(-50%);
  z-index: 3; white-space: nowrap;
  color: #fff; font-weight: 800; font-size: 0.95rem;
  padding: 8px 14px; border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  animation: bubble 1.8s ease forwards;
}
@keyframes bubble {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(0.9); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -12px); }
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat .emoji { font-size: 1.3rem; }
.stat .value { font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .label { font-size: 0.78rem; color: color-mix(in srgb, var(--ink) 60%, transparent); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg-bottom) 85%, #fff);
  border-top: 1px solid rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.tabs button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px; font-size: 0.72rem; font-weight: 700;
  color: color-mix(in srgb, var(--ink) 45%, transparent);
}
.tabs button .ico { font-size: 1.35rem; }
.tabs button.on { color: var(--primary); }

.banner {
  display: flex; gap: 12px; align-items: center;
  padding: 16px; border-radius: 24px; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  box-shadow: 0 12px 28px color-mix(in srgb, var(--primary) 40%, transparent);
  animation: slide-down 0.45s cubic-bezier(.2,.8,.2,1);
}
.banner .emoji { font-size: 2rem; }
@keyframes slide-down { from { transform: translateY(-120%); opacity: 0; } to { transform: none; opacity: 1; } }

.dots { display: flex; gap: 6px; justify-content: center; padding: 8px 0 4px; }
.dots i {
  display: block; height: 8px; width: 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 18%, transparent);
  transition: width 0.25s ease, background 0.25s ease;
}
.dots i.on {
  width: 22px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.theme-row { display: flex; gap: 12px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; }
.theme-row::-webkit-scrollbar { display: none; }
.theme-swatch {
  flex: 0 0 auto; width: 72px; text-align: center; font-size: 0.75rem; font-weight: 700;
}
.theme-swatch .swatch {
  width: 72px; height: 72px; border-radius: 18px; margin-bottom: 6px;
  display: grid; place-items: center; border: 3px solid transparent;
  background: linear-gradient(180deg, var(--t-top), var(--t-bottom));
}
.theme-swatch .swatch span {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--t-primary), var(--t-secondary));
}
.theme-swatch.on .swatch { border-color: var(--t-primary); }

.emoji-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px;
}
.emoji-grid button {
  aspect-ratio: 1; border-radius: 50%; font-size: 1.5rem;
  background: rgba(255, 255, 255, 0.6);
}
.emoji-grid button.on {
  background: color-mix(in srgb, var(--primary) 20%, transparent);
  outline: 2px solid var(--primary);
}

.goal-row { display: flex; gap: 14px; align-items: flex-start; padding: 6px 0; }
.goal-icon {
  position: relative; width: 52px; height: 52px; flex: 0 0 auto;
  border-radius: 50%; display: grid; place-items: center; font-size: 1.7rem;
  background: color-mix(in srgb, var(--secondary) 22%, transparent);
}
.goal-icon.done { background: color-mix(in srgb, var(--secondary) 55%, transparent); }
.goal-icon .badge {
  position: absolute; top: -4px; right: -6px;
  background: var(--primary); color: #fff;
  font-size: 0.65rem; font-weight: 800;
  padding: 2px 5px; border-radius: 999px;
}
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid color-mix(in srgb, var(--ink) 8%, transparent);
}
.list-item:last-child { border-bottom: 0; }
.trash {
  color: color-mix(in srgb, var(--primary) 70%, transparent);
  font-size: 1.1rem; padding: 6px;
}

dialog#sheet {
  border: 0; border-radius: 28px 28px 0 0; padding: 0;
  width: min(100vw, 560px); max-height: 92dvh;
  margin: auto 0 0; background: var(--bg-top);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.18);
}
dialog#sheet::backdrop { background: rgba(40, 16, 28, 0.35); backdrop-filter: blur(2px); }
dialog#sheet[open] { animation: sheet-up 0.3s ease; }
@keyframes sheet-up { from { transform: translateY(40%); } to { transform: none; } }
.sheet-body { padding: 20px 20px calc(24px + var(--safe-bottom)); overflow: auto; max-height: 92dvh; }
.sheet-handle {
  width: 40px; height: 5px; border-radius: 999px; margin: 10px auto 0;
  background: color-mix(in srgb, var(--ink) 20%, transparent);
}

.install-tip {
  margin-top: 14px; padding: 14px 16px; border-radius: 20px;
  background: color-mix(in srgb, var(--primary) 10%, #fff);
  font-size: 0.9rem; line-height: 1.4;
}
.install-tip strong { color: var(--primary); }

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