:root {
  --bg1: #fff1f4;
  --bg2: #f3ecff;
  --card: #ffffff;
  --text: #3a2e3a;
  --muted: #8a7a8a;
  --pink: #ff6f91;
  --pink-dark: #e0537a;
  --purple: #9d7cf0;
  --gold: #f4b942;
  --green: #4caf87;
  --red: #e0637a;
  --border: #f0e2ea;
  --shadow: 0 8px 24px rgba(157, 90, 130, 0.12);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 100%);
  background-attachment: fixed;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 90px;
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px 18px;
}
.app-title {
  font-family: 'Quicksand', 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 22px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--pink-dark);
}
.icon-btn {
  border: none;
  background: var(--card);
  box-shadow: var(--shadow);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.94); }

/* ---------- Balance strip ---------- */
.balances {
  display: flex;
  gap: 12px;
  margin-bottom: 18px;
}
.balance-card {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  border: 2px solid transparent;
}
.balance-card.me { border-color: var(--pink); }
.balance-card .name {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.balance-card .points {
  font-size: 24px;
  font-weight: 800;
  color: var(--pink-dark);
  margin-top: 2px;
}
.balance-card .points span { font-size: 14px; font-weight: 700; color: var(--gold); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 6px;
  background: var(--card);
  border-radius: 14px;
  padding: 5px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.tab-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px 4px;
  border-radius: 10px;
  font-family: inherit;
  font-weight: 700;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active {
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
}

.view { display: none; }
.view.active { display: block; }

/* ---------- Section headers ---------- */
.section-title {
  font-weight: 800;
  font-size: 15px;
  color: var(--muted);
  margin: 18px 4px 10px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.section-title:first-child { margin-top: 0; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.task-card { border-left: 5px solid var(--purple); }
.task-card.mine { border-left-color: var(--pink); }
.task-card.confirmed { opacity: .6; }
.task-card.pending { border-left-color: var(--gold); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
.card-title { font-weight: 800; font-size: 16px; }
.card-desc { color: var(--muted); font-size: 14px; margin-top: 4px; line-height: 1.4; }
.reward-badge {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--gold), #ffd27a);
  color: #5a4200;
  font-weight: 800;
  font-size: 13px;
  padding: 5px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}
.status-pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 20px;
  background: #f0e2ea;
  color: var(--muted);
}
.status-pill.pending { background: #fff3d6; color: #a3790c; }
.status-pill.confirmed { background: #e2f6ec; color: var(--green); }

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 16px;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: linear-gradient(135deg, var(--pink), var(--purple)); color: white; flex: 1; }
.btn-ghost { background: #f5eef2; color: var(--text); }
.btn-ghost.reject { color: var(--red); }
.btn-outline { background: transparent; border: 2px solid var(--pink); color: var(--pink-dark); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.fab {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 608px;
  width: calc(100% - 32px);
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
  border: none;
  border-radius: 16px;
  padding: 15px;
  font-family: inherit;
  font-weight: 800;
  font-size: 15px;
  box-shadow: 0 10px 26px rgba(157, 90, 130, 0.35);
  cursor: pointer;
  z-index: 20;
}

/* ---------- Shop ---------- */
.shop-item .card-top { align-items: center; }
.shop-item .cost-badge {
  background: linear-gradient(135deg, var(--purple), #b79bff);
  color: white;
}

/* ---------- Kitchen ---------- */
.meal-card { border-left: 5px solid var(--gold); }
.meal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.meal-emoji {
  width: 46px; height: 46px;
  border-radius: 14px;
  background: linear-gradient(135deg, #fff3d6, #ffe3ec);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.meal-info { flex: 1; }
.meal-type { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.meal-title { font-weight: 800; font-size: 16px; margin-top: 1px; }
.meal-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.meal-chevron { font-size: 13px; color: var(--muted); transition: transform .2s; flex-shrink: 0; }
.meal-card.expanded .meal-chevron { transform: rotate(180deg); }

.meal-reroll {
  border: none;
  background: #f5eef2;
  width: 34px; height: 34px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}
.meal-reroll:active { transform: scale(0.9) rotate(45deg); }
.meal-reroll.spinning { animation: spin .5s linear; }
@keyframes spin { to { transform: rotate(360deg); } }

.meal-body { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.meal-card.expanded .meal-body { display: block; animation: fadeSlideIn .25s ease-out both; }

.kbju-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}
.kbju-cell {
  background: #f5eef2;
  border-radius: 12px;
  padding: 8px 4px;
  text-align: center;
}
.kbju-cell .val { font-weight: 800; font-size: 15px; color: var(--pink-dark); }
.kbju-cell .lbl { font-size: 10px; color: var(--muted); font-weight: 700; text-transform: uppercase; margin-top: 1px; }

.meal-section-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin: 14px 0 8px;
}
.meal-section-label:first-child { margin-top: 0; }

.ingredient-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  font-size: 14px;
  border-bottom: 1px dashed var(--border);
}
.ingredient-row:last-child { border-bottom: none; }
.ingredient-amount { color: var(--muted); font-size: 13px; white-space: nowrap; }

.steps-list { margin: 0; padding-left: 20px; }
.steps-list li { font-size: 14px; line-height: 1.5; margin-bottom: 8px; color: var(--text); }
.steps-list li:last-child { margin-bottom: 0; }

.buy-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.buy-label { font-size: 12px; color: var(--muted); font-weight: 700; margin-right: 2px; }
.store-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  color: white;
}
.store-badge.st-5ka { background: #f39200; }
.store-badge.st-perek { background: #2e8b3d; }
.store-badge.st-lavka { background: #ffcc00; color: #2b2b2b; }
.store-badge.st-samokat { background: #2b2b2b; }

/* ---------- History ---------- */
.history-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: none; }
.history-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: #f5eef2;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.history-text { flex: 1; font-size: 14px; }
.history-text .who { font-weight: 700; }
.history-date { font-size: 11px; color: var(--muted); }
.history-amount { font-weight: 800; font-size: 14px; }
.history-amount.plus { color: var(--green); }
.history-amount.minus { color: var(--red); }

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 14px;
}
.empty .emoji { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- Overlay / modal ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(58, 46, 58, 0.45);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.overlay.active { display: flex; }
.sheet {
  background: var(--bg1);
  width: 100%;
  max-width: 640px;
  border-radius: 22px 22px 0 0;
  padding: 22px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  max-height: 86vh;
  overflow-y: auto;
  animation: slideUp .22s ease-out;
}
@keyframes slideUp { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet h2 { margin: 0 0 16px; font-family: 'Quicksand', sans-serif; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid var(--border);
  font-family: inherit;
  font-size: 15px;
  background: var(--card);
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 70px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--pink); }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }

.assign-note {
  background: #f5eef2;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ===================================================================
   Экран входа
   =================================================================== */
.login-screen {
  position: fixed;
  inset: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(135deg, #ffd6e0 0%, #ffc2d6 25%, #d9c3ff 60%, #c3d4ff 100%);
  background-size: 300% 300%;
  animation: gradientShift 14s ease infinite;
  padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.bg-blobs { position: absolute; inset: 0; z-index: 0; }
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(50px);
  opacity: .55;
}
.blob-a {
  width: 320px; height: 320px;
  background: radial-gradient(circle, #ff9ebb, transparent 70%);
  top: -80px; left: -80px;
  animation: floatBlob 11s ease-in-out infinite;
}
.blob-b {
  width: 360px; height: 360px;
  background: radial-gradient(circle, #b79bff, transparent 70%);
  bottom: -100px; right: -100px;
  animation: floatBlob 13s ease-in-out infinite reverse;
}
@keyframes floatBlob {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(30px, -20px) scale(1.08); }
}

.floaties {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.floaty {
  position: absolute;
  bottom: -40px;
  font-size: 22px;
  opacity: 0;
  animation-name: floatUp;
  animation-timing-function: ease-in;
  animation-iteration-count: infinite;
}
@keyframes floatUp {
  0%   { transform: translateY(0) translateX(0) rotate(0deg); opacity: 0; }
  10%  { opacity: .8; }
  90%  { opacity: .5; }
  100% { transform: translateY(-115vh) translateX(var(--drift, 20px)) rotate(25deg); opacity: 0; }
}

.login-content {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 380px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.login-logo-heart {
  display: inline-block;
  font-size: 54px;
  animation: heartbeat 2.2s ease-in-out infinite;
  filter: drop-shadow(0 6px 14px rgba(224, 83, 122, 0.35));
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.15); }
  30% { transform: scale(0.98); }
  45% { transform: scale(1.1); }
  60% { transform: scale(1); }
}

.login-title {
  font-family: 'Quicksand', sans-serif;
  font-weight: 700;
  font-size: 30px;
  color: #7a3b57;
  margin: 14px 0 4px;
  animation: fadeSlideIn .6s ease-out both;
}
.login-subtitle {
  color: #8c6b81;
  font-size: 14.5px;
  margin: 0 0 28px;
  animation: fadeSlideIn .6s ease-out .08s both;
}

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

/* --- Шаг 1: выбор профиля --- */
.profile-step {
  display: flex;
  gap: 16px;
  width: 100%;
  animation: fadeSlideIn .6s ease-out .16s both;
}
.profile-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(8px);
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  padding: 22px 12px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 10px 26px rgba(157, 90, 130, 0.16);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}
.profile-btn:hover { transform: translateY(-4px); box-shadow: 0 16px 32px rgba(157, 90, 130, 0.22); }
.profile-btn:active { transform: translateY(-1px) scale(0.97); }
.profile-btn.selected { border-color: var(--pink); }
.profile-avatar {
  width: 64px; height: 64px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffe3ec, #f1e6ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.6);
}
.profile-name {
  font-weight: 800;
  font-size: 15px;
  color: #5c3a4d;
}

/* --- Шаг 2: пароль --- */
.password-step {
  width: 100%;
  display: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
.password-step.active { display: flex; animation: fadeSlideIn .35s ease-out both; }
.profile-step.hidden { display: none; }

.back-btn {
  border: none;
  background: transparent;
  color: #8c6b81;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 2px;
}

.password-card {
  width: 100%;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  padding: 26px 22px 22px;
  box-shadow: 0 14px 34px rgba(157, 90, 130, 0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}
.password-card.shake { animation: shake .45s; }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}

.password-avatar {
  width: 68px; height: 68px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffe3ec, #f1e6ff);
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  margin-bottom: 10px;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.6);
}
.password-hello {
  font-weight: 800;
  font-size: 17px;
  color: #5c3a4d;
  margin-bottom: 16px;
}

.password-field { width: 100%; margin-bottom: 14px; }
.password-field input {
  text-align: center;
  letter-spacing: 4px;
  font-size: 18px;
  font-weight: 700;
  border: 2px solid var(--border);
  background: #fff;
}
.password-field input:focus { border-color: var(--pink); }

.login-error {
  min-height: 18px;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
  margin-top: 10px;
}

@media (prefers-reduced-motion: reduce) {
  .login-screen, .blob, .floaty, .login-logo-heart { animation: none !important; }
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: #3a2e3a;
  color: white;
  padding: 10px 18px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 700;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }
