/* Pixel Pet — estilos mobile-first (iPhone), estética retro 8-bit. */

:root {
  --shell: #f59e0b;
  --shell-dark: #b45309;
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --border: #38496b;
  --text: #e8edf6;
  --text-2: #94a3b8;
  --accent: #f59e0b;
  --comida: #f59e0b;
  --energia: #60a5fa;
  --carino: #f472b6;
  --err: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

/* El atributo hidden debe ganar SIEMPRE a cualquier display de estas reglas
   (sin esto, .sheet { display:flex } dejaba los paneles abiertos tapándolo todo). */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100dvh;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 16px);
}

h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}

/* ---------- sprites ---------- */

.sprite-svg { overflow: visible; display: block; }

.sprite {
  transform-box: fill-box;
  transform-origin: 50% 100%;
}

.blink { opacity: 0; animation: blink 3.4s steps(1) infinite; }

.anim-contento .sprite { animation: breathe 2.6s ease-in-out infinite; }
.anim-jugando .sprite { animation: bounce 0.5s ease-in-out infinite; }
.anim-dormido .sprite { animation: snooze 3.6s ease-in-out infinite; }
.anim-enfadado .sprite { animation: grumble 2.4s ease-in-out infinite; }

@keyframes blink {
  0%, 93% { opacity: 0; }
  94%, 99% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes breathe {
  0%, 100% { transform: scaleY(1); }
  50% { transform: scaleY(1.04) scaleX(0.99); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) scaleY(1); }
  30% { transform: translateY(-14%) scaleY(1.05) scaleX(0.97); }
  60% { transform: translateY(0) scaleY(0.9) scaleX(1.06); }
}
@keyframes snooze {
  0%, 100% { transform: scaleY(0.96); }
  50% { transform: scaleY(1.02); }
}
@keyframes grumble {
  0%, 84%, 100% { transform: translateX(0); }
  86% { transform: translateX(-3%); }
  89% { transform: translateX(3%); }
  92% { transform: translateX(-3%); }
  95% { transform: translateX(2%); }
}

@media (prefers-reduced-motion: reduce) {
  .sprite, .blink, .zzz, .poop { animation: none !important; }
}

/* ---------- pantalla inicial ---------- */

.setup {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  text-align: center;
  padding-top: 24px;
}

.hint { color: var(--text-2); margin: 4px 0 0; font-size: 0.85rem; }

.pick-animals, .pick-colors {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  min-width: 86px;
  min-height: 44px;
  font-size: 0.8rem;
  color: var(--text-2);
}
.pick.active { border-color: var(--accent); color: var(--text); background: var(--panel-2); }
.pick .sprite-svg { width: 48px; height: 48px; }
.pick .dot { width: 22px; height: 22px; border-radius: 4px; display: block; }

.preview .sprite-svg { width: 120px; height: 120px; }

.name-label { color: var(--text-2); font-size: 0.85rem; }

.setup input {
  width: 100%;
  max-width: 280px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  text-align: center;
  padding: 12px;
  outline: none;
}
.setup input:focus { border-color: var(--accent); }

.btn-start {
  background: var(--accent);
  color: #1c1917;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 1px;
  border-radius: 12px;
  padding: 14px 28px;
  min-height: 48px;
  box-shadow: 0 4px 0 #b45309;
}
.btn-start:active { transform: translateY(2px); box-shadow: 0 2px 0 #b45309; }

/* ---------- juego: carcasa tipo tamagotchi ---------- */

.game { display: flex; flex-direction: column; gap: 10px; flex: 1; justify-content: center; }

.device {
  background: linear-gradient(150deg, var(--shell), var(--shell-dark));
  border: 3px solid rgba(0, 0, 0, 0.55);
  border-radius: 56px 56px 72px 72px / 64px 64px 88px 88px;
  padding: 14px 16px 18px;
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.28),
    inset 0 -6px 12px rgba(0, 0, 0, 0.25),
    0 12px 28px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.shell-top { text-align: center; }
.shell-top h1 {
  font-size: 1rem;
  letter-spacing: 4px;
  color: rgba(0, 0, 0, 0.55);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

.screen {
  background: var(--bg);
  border: 8px solid #101726;
  border-radius: 18px;
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.7),
    inset 0 4px 14px rgba(0, 0, 0, 0.6),
    0 1px 0 rgba(255, 255, 255, 0.25);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

/* scanlines sutiles de LCD */
.screen::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 10px;
  background: repeating-linear-gradient(0deg, transparent 0 2px, rgba(0, 0, 0, 0.07) 2px 3px);
  pointer-events: none;
}

.icon-btn { position: relative; min-width: 44px; min-height: 44px; display: grid; place-items: center; }

.shell-keys { display: flex; justify-content: center; gap: 18px; }
.shell-keys .key {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(160deg, #2c3a52, #1a2435);
  border: 2px solid rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), 0 3px 0 rgba(0, 0, 0, 0.45);
}
.shell-keys .key:active { transform: translateY(2px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18), 0 1px 0 rgba(0, 0, 0, 0.45); }
.shell-keys .key .icon-svg { width: 20px; height: 20px; }

/* iconos pixel art de UI */
.icon-svg { width: 24px; height: 24px; display: block; }

.badge {
  position: absolute;
  top: 3px;
  right: 1px;
  min-width: 15px;
  height: 15px;
  line-height: 15px;
  background: var(--err);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 700;
  text-align: center;
  border-radius: 4px;
  padding: 0 2px;
}

.stage {
  position: relative;
  background: linear-gradient(#16213b, #1b2b4a);
  border-radius: 10px;
  height: clamp(170px, 26dvh, 230px);
  overflow: hidden;
}

.pet-slot {
  position: absolute;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
}
.pet-slot .sprite-svg { width: clamp(104px, 18dvh, 132px); height: auto; aspect-ratio: 1; }

.ground {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 36px;
  background: #233a2b;
  border-top: 4px solid #2f5038;
}

.poops { position: absolute; left: 0; right: 0; bottom: 30px; height: 24px; }
.poop {
  position: absolute;
  bottom: 0;
  width: 26px;
  animation: poop-in 0.3s ease-out;
}
.poop svg { width: 100%; display: block; }
@keyframes poop-in { from { transform: translateY(-8px); opacity: 0; } }

.zzz {
  position: absolute;
  top: 18px;
  right: 24px;
  color: var(--energia);
  font-weight: 700;
  letter-spacing: 3px;
  animation: zzz-float 2.4s ease-in-out infinite;
}
@keyframes zzz-float {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-8px); opacity: 1; }
}

.alert {
  position: absolute;
  top: 16px;
  left: calc(50% + 40px);
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  background: var(--err);
  color: #fff;
  font-weight: 700;
  border-radius: 4px;
  animation: alert-bounce 1s ease-in-out infinite;
  z-index: 2;
}
@keyframes alert-bounce { 50% { transform: translateY(-5px); } }

.mood-msg {
  margin: 0;
  text-align: center;
  color: var(--text-2);
  font-size: 0.9rem;
  min-height: 1.2em;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 14px);
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.85rem;
  z-index: 10;
  white-space: nowrap;
}

/* ---------- stats ---------- */

.stats { display: grid; gap: 8px; }

.stat { display: grid; grid-template-columns: 96px 1fr; align-items: center; gap: 8px; }
.stat-label { font-size: 0.8rem; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.stat-label .icon-svg { width: 14px; height: 14px; flex: none; }

.bar {
  height: 16px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.fill { height: 100%; transition: width 0.6s ease; }
.fill-comida { background: var(--comida); }
.fill-energia { background: var(--energia); }
.fill-carino { background: var(--carino); }
.fill.low { background: var(--err); animation: low-pulse 1.2s ease-in-out infinite; }
@keyframes low-pulse { 50% { opacity: 0.45; } }

/* ---------- acciones ---------- */

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding-bottom: 16px; /* sitio para las etiquetas bajo los botones */
}

/* botones "físicos" redondos */
.actions .btn {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(160deg, #32415c, #1a2435);
  border: 2px solid rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 4px 0 rgba(0, 0, 0, 0.5);
}
.actions .btn .icon-svg { width: 24px; height: 24px; }
.actions .btn span {
  position: absolute;
  top: calc(100% + 3px);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.58rem;
  color: rgba(0, 0, 0, 0.6);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.3);
  letter-spacing: 0.5px;
  font-weight: 700;
  text-transform: uppercase;
}
.actions .btn:active { transform: translateY(3px); box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 1px 0 rgba(0, 0, 0, 0.5); }

.foot { margin-top: auto; text-align: center; padding-top: 8px; }
.link { color: var(--text-2); font-size: 0.75rem; text-decoration: underline; min-height: 44px; }

/* ---------- recordatorios ---------- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 25, 0.72);
  z-index: 20;
  display: flex;
  align-items: flex-end;
}

.sheet-card {
  background: var(--panel);
  border: 2px solid var(--border);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--safe-bottom) + 16px);
  max-height: 78dvh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; font-size: 1rem; letter-spacing: 2px; text-transform: uppercase; }
.sheet-hint { margin: 0; color: var(--text-2); font-size: 0.75rem; }

.chore-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 40px;
}

.chore {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.chore.due { border-color: var(--err); }

.chore-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.chore-title { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chore-when { font-size: 0.7rem; color: var(--text-2); }
.chore.due .chore-when { color: var(--err); }

.chore-btns { display: flex; align-items: center; gap: 4px; flex: none; }
.chore-done {
  background: var(--accent);
  color: #1c1917;
  font-weight: 700;
  font-size: 0.75rem;
  border-radius: 8px;
  padding: 10px 12px;
}
.chore-del { color: var(--text-2); font-size: 0.7rem; text-decoration: underline; padding: 10px 6px; }

.chore-empty { color: var(--text-2); font-size: 0.85rem; text-align: center; padding: 10px 0; }

.chore-form { display: flex; flex-direction: column; gap: 8px; }
.chore-form input[name='title'] {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 11px 12px;
  outline: none;
}
.chore-form input[name='title']:focus { border-color: var(--accent); }
.chore-form .row { display: flex; gap: 8px; }
.chore-form select,
.chore-form input[type='time'] {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  padding: 10px;
  outline: none;
}
.btn-add {
  background: var(--accent);
  color: #1c1917;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 10px;
  padding: 12px;
  min-height: 44px;
}

/* ---------- compartir ---------- */

.share-body { display: flex; flex-direction: column; gap: 12px; }

.share-live {
  background: var(--panel-2);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.share-live-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; }

.share-url {
  display: block;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.7rem;
  word-break: break-all;
  color: var(--energia);
}

.share-row { display: flex; gap: 8px; }
.share-row .chore-done { flex: 1; }

/* ---------- página en directo (/s/:id) ---------- */

.live-page { justify-content: center; }

.live-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 20px 16px;
}
.live-card h1 { letter-spacing: 3px; }

.live-stage {
  position: relative;
  background: linear-gradient(#16213b, #1b2b4a);
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 20px 0 12px;
  display: flex;
  justify-content: center;
}
.live-stage .sprite-svg { width: 130px; height: 130px; }
.live-stage .zzz { top: 10px; right: 16px; }

.live-card .stat-label { text-align: left; }
.live-updated { margin: 0; color: var(--text-2); font-size: 0.7rem; }

/* pantalla de error de arranque (index.html) */
.boot-error {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  justify-content: center;
  min-height: 70dvh;
  text-align: center;
  color: var(--text);
}
.boot-error button {
  background: var(--accent);
  color: #1c1917;
  font-weight: 700;
  border-radius: 10px;
  padding: 12px 22px;
  min-height: 44px;
}
