:root {
  --pink: #ff6b9d;
  --purple: #8b5cf6;
  --yellow: #ffd23f;
  --green: #4caf50;
  --blue: #4dabf7;
  --gray: #cfd4da;
  --bg: #fef6f0;
  --text: #3a2e39;
  --radius: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, "Comic Sans MS", sans-serif;
  background: linear-gradient(160deg, #fff2e0 0%, #ffe0ec 100%);
  color: var(--text);
  min-height: 100vh;
}

.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

/* ---------- Login ---------- */
#screen-login.active { display: flex; align-items: center; justify-content: center; }

.login-card {
  background: white;
  border-radius: 28px;
  padding: 32px 28px;
  width: min(92vw, 380px);
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.12);
}

.login-emoji { font-size: 56px; }
.login-card h1 { margin: 4px 0 0; font-size: 28px; color: var(--purple); }
.hint { color: #8a7f8a; font-size: 15px; margin: 6px 0 18px; }

.pin-display { display: flex; justify-content: center; gap: 14px; margin-bottom: 22px; }
.pin-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: #eee; border: 2px solid var(--gray);
  transition: background .15s, transform .15s;
}
.pin-dot.filled { background: var(--purple); border-color: var(--purple); transform: scale(1.1); }

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-key {
  font-size: 26px; font-weight: 700; padding: 18px 0; border-radius: 18px;
  border: none; background: #f3eefc; color: var(--purple);
  cursor: pointer; transition: transform .1s;
}
.pin-key:active { transform: scale(0.92); }
.pin-key-clear { background: #ffe3e3; color: #e03131; font-size: 20px; }
.pin-key-ok { background: var(--green); color: white; }

.login-error { color: #e03131; font-weight: 600; min-height: 20px; margin-top: 12px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 20px; background: var(--purple); color: white;
  font-size: 20px; font-weight: 700;
}
.topbar-admin { background: #495057; }
.btn-icon {
  background: rgba(255,255,255,0.2); border: none; color: white;
  font-size: 20px; padding: 8px 12px; border-radius: 12px; cursor: pointer;
}

.content { max-width: 640px; margin: 0 auto; padding: 16px; padding-bottom: 60px; }

.card {
  background: white; border-radius: var(--radius); padding: 18px;
  margin-bottom: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.card h2 { margin-top: 0; font-size: 18px; color: var(--purple); }

/* ---------- Sparschwein ---------- */
.piggy-card { text-align: center; }
.piggy-wrap {
  position: relative; width: 160px; height: 160px; margin: 0 auto 8px;
  border-radius: 50%; background: #f1eefc; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  border: 4px solid #f3eefc;
}
.piggy-fill {
  position: absolute; bottom: 0; left: 0; right: 0; height: 0%;
  background: linear-gradient(180deg, #ffe66d, #ffd23f);
  transition: height .6s ease;
}
.piggy-emoji { position: relative; font-size: 64px; z-index: 1; }
.piggy-amount { font-size: 30px; font-weight: 800; color: var(--purple); margin: 4px 0 14px; }

.goal-row { text-align: left; }
.goal-name { font-weight: 700; margin-bottom: 6px; }
.goal-bar { background: #f1eefc; border-radius: 999px; height: 18px; overflow: hidden; }
.goal-bar-fill {
  height: 100%; width: 0%; background: linear-gradient(90deg, var(--pink), var(--purple));
  transition: width .6s ease; border-radius: 999px;
}
.goal-text { font-size: 13px; color: #8a7f8a; margin-top: 4px; }

/* ---------- Offene Sonntage ---------- */
.open-list { display: flex; flex-direction: column; gap: 10px; }
.open-item {
  display: flex; justify-content: space-between; align-items: center;
  background: #fff8e1; border: 2px dashed var(--yellow); border-radius: 14px;
  padding: 12px 14px;
}
.open-item span { font-weight: 700; }
.open-item button {
  background: var(--yellow); border: none; border-radius: 10px;
  padding: 8px 14px; font-weight: 700; cursor: pointer;
}

/* ---------- Aktionen ---------- */
.actions-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.btn {
  border: none; border-radius: 14px; padding: 12px 18px; font-size: 15px;
  font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--purple); color: white; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-secondary { background: #f1eefc; color: var(--purple); }
.btn-text { background: none; color: #8a7f8a; }
.file-btn { display: inline-flex; align-items: center; gap: 6px; }

/* ---------- Kalender ---------- */
.calendar-header {
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; margin-bottom: 10px;
}
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center;
}
.cal-day {
  padding: 8px 0; border-radius: 10px; font-size: 13px; position: relative;
}
.cal-day.empty { visibility: hidden; }
.cal-day.today { border: 2px solid var(--purple); }
.cal-day.sunday-done { background: #d3f9d8; color: #2b8a3e; font-weight: 700; }
.cal-day.sunday-open { background: #fff3bf; color: #e67700; font-weight: 700; animation: blink 1.4s infinite; }
.cal-day.sunday-future { background: #f1f3f5; color: #868e96; }

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.legend { display: flex; gap: 14px; margin-top: 10px; font-size: 12px; color: #8a7f8a; flex-wrap: wrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 4px; }
.dot-green { background: #4caf50; }
.dot-yellow { background: var(--yellow); }
.dot-gray { background: var(--gray); }

/* ---------- Recent / History ---------- */
.recent-list, .admin-history { display: flex; flex-direction: column; gap: 10px; }
.recent-item, .admin-item {
  display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; background: #faf8fc;
}
.recent-item img, .admin-item img {
  width: 46px; height: 46px; border-radius: 50%; object-fit: cover; background: #eee;
}
.recent-item .info, .admin-item .info { flex: 1; }
.recent-item .amount, .admin-item .amount { font-weight: 800; color: var(--purple); }
.admin-item button.del {
  background: #ffe3e3; color: #e03131; border: none; border-radius: 10px; padding: 6px 10px; cursor: pointer;
}

/* ---------- Forms (Admin) ---------- */
.form-grid { display: grid; gap: 12px; }
.form-grid label, .form-inline label { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; gap: 4px; }
.form-grid input, .form-inline input {
  padding: 10px 12px; border-radius: 10px; border: 1px solid #ddd; font-size: 15px;
}
.form-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.msg { font-weight: 600; color: var(--green); min-height: 18px; }
.hint-small { color: #8a7f8a; font-size: 13px; }
.avatar-upload-row { display: flex; gap: 24px; }

/* ---------- Modal ---------- */
.modal {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal.active { display: flex; }
.modal-box {
  background: white; border-radius: 24px; padding: 24px; width: min(92vw, 420px);
  max-height: 90vh; overflow-y: auto;
}
.modal-box label { display: block; font-size: 13px; font-weight: 700; margin: 10px 0 4px; }
.modal-box input[type=text] { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid #ddd; font-size: 15px; }

.payer-row { display: flex; gap: 12px; margin: 10px 0; }
.payer-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 14px; border-radius: 16px; border: 3px solid #eee; background: white; cursor: pointer;
}
.payer-btn.selected { border-color: var(--purple); background: #f3eefc; }
.avatar-img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.avatar-fallback { font-size: 40px; }
.payer-btn img.avatar-img[style*="display: none"] + .avatar-fallback { display: block; }

.photo-row { display: flex; align-items: center; gap: 10px; margin: 14px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Success overlay ---------- */
.success-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  align-items: center; justify-content: center; overflow: hidden;
}
.success-overlay.active { display: flex; }
.success-box {
  background: white; border-radius: 24px; padding: 32px; text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2); z-index: 2;
}
.success-emoji { font-size: 60px; }
.success-text { font-size: 22px; font-weight: 800; color: var(--purple); margin-top: 8px; }

.confetti-container { position: absolute; inset: 0; pointer-events: none; }
.confetti-piece {
  position: absolute; top: -20px; width: 10px; height: 14px; opacity: 0.9;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(360deg); opacity: 0.3; }
}

@media (max-width: 420px) {
  .avatar-upload-row { flex-direction: column; gap: 10px; }
}
