:root {
  --pink: #ff5c9a;
  --pink-light: #ff8fc0;
  --pink-dark: #d63b78;
  --purple: #8b5cf6;
  --ink: #3a2a4a;
  --muted: #8a7a9a;
  --card: #ffffff;
  --line: #f0e6f5;
  --bg-top: #ffe3f1;
  --bg-bottom: #e3eeff;
  --gold: #ffb800;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(90, 40, 110, 0.08), 0 10px 24px rgba(90, 40, 110, 0.08);
  --nav-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

html, body { margin: 0; }

body {
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom)) fixed;
  background-color: var(--bg-top);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; color: inherit; }

#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; }

.screen {
  padding: 12px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: fadeIn 0.25s ease;
}
.screen-login, .screen-editor { padding-bottom: calc(var(--safe-b) + 24px); padding-top: calc(var(--safe-t) + 16px); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1, h2 { margin: 0; }
.title, .brand, .pet-name, .modal-title { font-family: 'Titan One', 'Fredoka', sans-serif; font-weight: 400; letter-spacing: 0.3px; }
.title { font-size: 1.7rem; color: var(--pink-dark); }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.8rem; }
.center { text-align: center; }
.label { font-weight: 600; margin: 4px 0 6px; display: block; font-size: 0.95rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; }

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

/* ───────── Botones ───────── */
.btn {
  border: none;
  border-radius: 16px;
  padding: 12px 18px;
  font-weight: 600;
  background: #fff;
  box-shadow: 0 4px 0 #e6d8ee;
  transition: transform 0.08s, box-shadow 0.08s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 #e6d8ee; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(180deg, var(--pink-light), var(--pink)); color: #fff; box-shadow: 0 5px 0 var(--pink-dark); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.12); }
.btn-primary:active:not(:disabled) { box-shadow: 0 2px 0 var(--pink-dark); }
.btn-danger { color: #d63b4b; }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 18px; font-size: 1.1rem; }
.btn-sm { padding: 8px 12px; font-size: 0.9rem; border-radius: 12px; }
.btn small { font-weight: 500; opacity: 0.85; }

.icon-btn {
  border: none;
  background: #fff;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  box-shadow: 0 3px 0 #e6d8ee;
  font-size: 1.15rem;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

input:not([type=color]) {
  width: 100%;
  border: 2px solid var(--line);
  background: #fbf8fd;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 1rem;
  outline: none;
  margin-bottom: 10px;
}
input:focus { border-color: var(--pink-light); background: #fff; }
.form-error { color: #d63b4b; min-height: 1.2em; margin: 0 0 8px; font-size: 0.9rem; }

/* ───────── Haba ───────── */
.bean { width: 100%; height: 100%; display: block; overflow: visible; }
.bean-bob { transform-box: fill-box; transform-origin: 50% 100%; animation: bob 2.8s ease-in-out infinite; }
.blink { transform-box: fill-box; transform-origin: center; animation: blink 5s infinite; }
@keyframes bob { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(1.025, 0.975); } }
@keyframes blink { 0%, 93%, 100% { transform: scaleY(1); } 95.5% { transform: scaleY(0.1); } }

/* ───────── Login ───────── */
.login-hero { text-align: center; }
.login-logo { width: 130px; height: 140px; margin: 0 auto; }
.brand { font-size: 2.6rem; color: var(--pink); text-shadow: 0 4px 0 #fff, 0 6px 0 rgba(214, 59, 120, 0.25); }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.who-btn {
  border: 3px solid var(--line);
  background: #fbf8fd;
  border-radius: 18px;
  padding: 10px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: border-color 0.15s, transform 0.15s;
  min-width: 0;
}
.who-btn b { font-size: 0.9rem; word-break: break-all; }
.who-btn small { color: var(--muted); }
.who-btn.selected { border-color: var(--pink); background: #fff0f7; transform: translateY(-2px); }
.who-pet { width: 80px; height: 86px; display: block; }

/* ───────── Topbar / nav ───────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: rgba(255, 238, 247, 0.85);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.topbar-user { border: none; background: none; display: flex; align-items: center; gap: 6px; font-weight: 600; padding: 0; min-width: 0; font-size: 0.9rem; }
.topbar-user > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-avatar { width: 34px; height: 36px; display: block; flex-shrink: 0; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.pill { background: #fff; border-radius: 999px; padding: 6px 10px; font-size: 0.9rem; box-shadow: 0 3px 0 #e6d8ee; white-space: nowrap; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: #fff;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -6px 24px rgba(90, 40, 110, 0.1);
  padding: 6px 6px calc(6px + var(--safe-b));
  height: calc(var(--nav-h) + var(--safe-b));
}
.bottom-nav button {
  border: none;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 16px;
  position: relative;
  color: var(--muted);
}
.bottom-nav .nav-icon { font-size: 1.35rem; transition: transform 0.15s; }
.bottom-nav small { font-size: 0.72rem; font-weight: 600; }
.bottom-nav button.active { color: var(--pink-dark); background: #fff0f7; }
.bottom-nav button.active .nav-icon { transform: translateY(-2px) scale(1.1); }
.badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 22px);
  background: var(--pink);
  color: #fff;
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  padding: 0 4px;
}
.badge[hidden] { display: none; }

/* ───────── Escenario ───────── */
.stage {
  position: relative;
  border-radius: 28px;
  padding: 16px 16px 12px;
  background:
    radial-gradient(ellipse 70% 22% at 50% 98%, #9be38d 0 60%, transparent 61%),
    radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.9) 0 18px, transparent 19px),
    radial-gradient(circle at 25% 20%, rgba(255, 255, 255, 0.9) 0 14px, transparent 15px),
    radial-gradient(circle at 82% 30%, rgba(255, 255, 255, 0.8) 0 12px, transparent 13px),
    linear-gradient(180deg, #a9dcff, #e6f6ff 75%);
  box-shadow: var(--shadow);
  overflow: hidden;
  text-align: center;
}
.stage-partner { background:
    radial-gradient(ellipse 70% 22% at 50% 98%, #ffc2dd 0 60%, transparent 61%),
    linear-gradient(180deg, #ffd6ea, #fff1f8 75%); }
.stage-head { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.pet-name { font-size: 1.8rem; color: #fff; text-shadow: 0 3px 0 rgba(58, 42, 74, 0.35); word-break: break-word; }
.stage-partner .pet-name { color: var(--pink-dark); text-shadow: 0 2px 0 #fff; }
.chip-mood { background: rgba(255, 255, 255, 0.85); border-radius: 999px; padding: 4px 10px; font-size: 0.85rem; font-weight: 600; }
.stage-sub { font-weight: 600; color: rgba(58, 42, 74, 0.7); font-size: 0.9rem; margin-top: 2px; }
.stage-hint { margin: 0; font-size: 0.8rem; color: rgba(58, 42, 74, 0.6); }
.pet-wrap { display: block; width: min(260px, 70vw); height: min(280px, 75vw); margin: 4px auto 0; border: none; background: none; padding: 0; touch-action: manipulation; }
.pet-wrap.jump { animation: jump 0.6s cubic-bezier(.3, 1.6, .5, 1); }
.pet-wrap.snooze { animation: snooze 2.4s ease-in-out; }
@keyframes jump {
  0% { transform: translateY(0) scale(1, 1); }
  20% { transform: translateY(0) scale(1.1, 0.88); }
  50% { transform: translateY(-28px) scale(0.94, 1.08); }
  80% { transform: translateY(0) scale(1.06, 0.94); }
  100% { transform: translateY(0) scale(1, 1); }
}
@keyframes snooze { 0%, 100% { transform: rotate(0); } 30%, 70% { transform: rotate(-6deg) translateY(4px); } }

.fx { position: absolute; inset: 0; pointer-events: none; }
.burst {
  position: absolute;
  top: 48%;
  font-size: 1.6rem;
  animation: burst 1.4s ease-out forwards;
  opacity: 0;
}
@keyframes burst {
  0% { transform: translate(0, 0) scale(0.4); opacity: 0; }
  15% { opacity: 1; }
  100% { transform: translate(var(--dx), -150px) scale(1.2); opacity: 0; }
}
.float-text {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  font-weight: 700;
  color: #fff;
  background: rgba(58, 42, 74, 0.55);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  animation: floatUp 1.4s ease-out forwards;
}
@keyframes floatUp { from { opacity: 0; transform: translate(-50%, 10px); } 20% { opacity: 1; } to { opacity: 0; transform: translate(-50%, -50px); } }

/* ───────── Barras ───────── */
.bar { height: 14px; background: #f1e9f6; border-radius: 999px; overflow: hidden; margin: 6px 0; }
.bar i { display: block; height: 100%; border-radius: inherit; transition: width 0.5s ease; min-width: 6px; }
.bar-exp i { background: linear-gradient(90deg, #ffd93d, #ffb800); }
.bar-hambre i { background: linear-gradient(90deg, #ff9f9f, #ff5c6c); }
.bar-felicidad i { background: linear-gradient(90deg, #ffe58a, #ffc93d); }
.bar-energia i { background: linear-gradient(90deg, #9fd8ff, #4a9cff); }
.bar-mission i { background: linear-gradient(90deg, var(--pink-light), var(--pink)); }
.needs { display: flex; flex-direction: column; gap: 4px; }
.need { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 8px; }
.need-label { font-weight: 600; font-size: 0.92rem; }

/* ───────── Acciones ───────── */
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.action-btn {
  border: none;
  background: #fff;
  border-radius: 18px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-weight: 600;
  font-size: 0.85rem;
  box-shadow: 0 4px 0 #e6d8ee;
  transition: transform 0.08s, box-shadow 0.08s;
  min-width: 0;
}
.action-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #e6d8ee; }
.action-emoji { font-size: 1.7rem; }
.action-btn small { color: var(--muted); font-size: 0.7rem; font-weight: 500; white-space: nowrap; }
.action-btn.cooling { opacity: 0.6; }
.time-note { text-align: center; margin: 0; font-size: 0.9rem; }

/* ───────── Editor ───────── */
.editor-head { display: flex; gap: 10px; align-items: flex-start; }
.editor-preview {
  position: sticky;
  top: 0;
  z-index: 5;
  height: 230px;
  border-radius: 28px;
  background: radial-gradient(ellipse 60% 18% at 50% 96%, rgba(155, 227, 141, 0.9) 0 60%, transparent 61%), linear-gradient(180deg, #a9dcff, #e6f6ff);
  box-shadow: var(--shadow);
  padding: 10px;
}
.editor-panel { display: flex; flex-direction: column; gap: 4px; }
.ed-section { padding: 6px 0; border-top: 2px dashed var(--line); }
.editor-actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; position: sticky; bottom: calc(var(--safe-b) + 10px); }
.editor-actions .btn { white-space: nowrap; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--c);
  box-shadow: 0 0 0 2px var(--line);
  padding: 0;
  position: relative;
  transition: transform 0.12s;
}
.swatch.selected { box-shadow: 0 0 0 3px var(--pink); transform: scale(1.1); }
.swatch-custom { display: grid; place-items: center; overflow: hidden; cursor: pointer; background: conic-gradient(#ff5c6c, #ffd93d, #6bd968, #5bc0f8, #a66bff, #ff5c6c); }
.swatch-custom.selected { background: var(--c); }
.swatch-custom span { font-weight: 700; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); pointer-events: none; }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; border: none; padding: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 2px solid var(--line);
  background: #fbf8fd;
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 500;
  font-size: 0.9rem;
}
.chip.selected { border-color: var(--pink); background: #fff0f7; color: var(--pink-dark); font-weight: 600; }

/* ───────── Pestañas ───────── */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 6px; scrollbar-width: none; margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: none;
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 3px 0 #e6d8ee;
  flex-shrink: 0;
}
.tab.active { background: var(--pink); color: #fff; box-shadow: 0 3px 0 var(--pink-dark); }

/* ───────── Tienda ───────── */
.item-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 420px) { .item-grid { grid-template-columns: repeat(3, 1fr); } }
.item-card {
  border: none;
  background: #fff;
  border-radius: 20px;
  padding: 10px 8px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.item-card:active { transform: scale(0.97); }
.item-card.locked .item-preview { filter: grayscale(0.7) opacity(0.6); }
.item-preview { width: 100%; height: 120px; display: block; overflow: hidden; background: linear-gradient(180deg, #f3ecff, #fff); border-radius: 14px; padding: 6px; }
.item-preview .bean { overflow: hidden; }
.item-name { font-size: 0.9rem; text-align: center; line-height: 1.15; }
.tag { font-size: 0.8rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.tag-price { background: #fff5d6; color: #a06d00; }
.tag-price.poor { color: #c98b8b; background: #f8eeee; }
.tag-owned { background: #e2f8de; color: #2e8a3a; }
.tag-locked { background: #efe9f5; color: var(--muted); }
.lock-note { text-align: center; background: #f5f0fa; border-radius: 14px; padding: 12px; margin: 0; font-weight: 600; color: var(--muted); }

/* ───────── Armario ───────── */
.closet-preview { height: 230px; border-radius: 28px; background: linear-gradient(180deg, #f3ecff, #fff); box-shadow: var(--shadow); padding: 10px; }
.closet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.closet-item {
  border: 3px solid transparent;
  background: #fff;
  border-radius: 18px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: var(--shadow);
  min-width: 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}
.closet-item .item-preview { height: 86px; }
.closet-item.selected { border-color: var(--pink); }
.none-icon { height: 86px; display: grid; place-items: center; font-size: 2rem; }
.empty { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty p { margin: 0; }
.ghost-pet { width: 120px; height: 130px; opacity: 0.7; }

/* ───────── Misiones ───────── */
.mission-list { display: flex; flex-direction: column; gap: 10px; }
.mission { display: flex; gap: 12px; align-items: center; padding: 14px; }
.mission-main { flex: 1; min-width: 0; }
.mission-text { margin: 0; font-weight: 600; }
.mission-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.reward-tag { font-size: 0.8rem; font-weight: 700; color: #a06d00; background: #fff5d6; border-radius: 999px; padding: 3px 8px; white-space: nowrap; }
.claimed-tag { color: #2e8a3a; font-weight: 700; font-size: 0.85rem; }
.mission.ready { outline: 3px solid var(--pink-light); }
.mission.claimed { opacity: 0.6; }
.tips ul { margin: 8px 0; padding-left: 20px; line-height: 1.5; }

/* ───────── Pareja / ajustes ───────── */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; }
.stats-row b { display: block; font-size: 1.4rem; color: var(--pink-dark); }
.stats-row small { color: var(--muted); }
.profile-card { display: flex; align-items: center; gap: 14px; }
.profile-pet { width: 70px; height: 76px; display: block; flex-shrink: 0; }
#pwForm { display: flex; flex-direction: column; }

/* ───────── Modal ───────── */
#modal-root { position: fixed; inset: 0; z-index: 50; display: none; place-items: center; padding: 16px; }
#modal-root.open { display: grid; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(58, 42, 74, 0.45); animation: fadeIn 0.2s; }
.modal {
  position: relative;
  background: #fff;
  border-radius: 28px;
  padding: 22px 18px 18px;
  width: 100%;
  max-width: 380px;
  max-height: 90dvh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: pop 0.3s cubic-bezier(.3, 1.5, .5, 1);
}
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: none; opacity: 1; } }
.modal p { margin: 0; }
.modal-title { text-align: center; color: var(--pink-dark); font-size: 1.5rem; }
.modal-pet { height: 220px; background: linear-gradient(180deg, #e6f6ff, #fff); border-radius: 22px; padding: 8px; }
.modal-x { position: absolute; top: 10px; right: 10px; border: none; background: #f5f0fa; width: 34px; height: 34px; border-radius: 50%; z-index: 2; }
.reward { font-size: 1.6rem; font-weight: 700; color: #a06d00; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; border-radius: inherit; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(520px) rotate(540deg); opacity: 0.2; } }

/* ───────── Toasts ───────── */
#toast-root {
  position: fixed;
  top: calc(var(--safe-t) + 64px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 420px;
  pointer-events: none;
}
.toast {
  background: #fff;
  border-radius: 16px;
  padding: 12px 14px;
  box-shadow: 0 8px 24px rgba(58, 42, 74, 0.18);
  font-weight: 500;
  animation: toastIn 0.3s cubic-bezier(.3, 1.4, .5, 1);
  transition: opacity 0.3s, transform 0.3s;
  border-left: 5px solid var(--pink);
}
.toast.warn { border-left-color: #ffb800; }
.toast.ok { border-left-color: #6bd968; }
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-12px) scale(0.95); } to { opacity: 1; transform: none; } }

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