:root {
  color-scheme: light;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --silver: #94a3b8;
  --silver-dark: #64748b;
  --gold: #f5b93d;
  --gold-dark: #d99a1c;
  --red: #dc2626;
  --green: #16a34a;
  --bg: #f4f6f8;
  --card-bg: #ffffff;
  --text: #1a1a1a;
  --text-muted: #64748b;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

img { max-width: 100%; display: block; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ---------- Login (pantalla de bloqueo) ---------- */

#lock.card {
  max-width: 360px;
  margin: 20vh auto 0;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}

#lock h1 { font-size: 1.2rem; margin: 0 0 8px; text-align: center; }
#lock p { font-size: 0.9rem; color: var(--text-muted); margin: 0 0 20px; text-align: center; }

input[type="text"], input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  font-size: 0.95rem;
  margin-bottom: 12px;
  background: #fff;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  background: var(--blue);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
}
.btn:active { background: var(--blue-dark); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-danger { background: var(--red); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-block { display: block; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; width: auto; }

.error { color: var(--red); font-size: 0.85rem; margin-top: 10px; min-height: 1.2em; text-align: center; }

/* ---------- App shell ---------- */

#app { display: none; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--blue);
  color: #fff;
}

.app-header__left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header__back {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 1rem;
}

.app-header__title { font-size: 1.05rem; font-weight: 700; margin: 0; }

.wallet-mini {
  display: flex;
  gap: 10px;
  font-size: 0.85rem;
  font-weight: 600;
}
.wallet-mini span { display: flex; align-items: center; gap: 4px; }

.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 48px;
}

/* ---------- Home ---------- */

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin-top: 8px;
}

.home-btn {
  background: var(--card-bg);
  border: none;
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  padding: 24px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  text-align: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}
.home-btn__icon { font-size: 2.2rem; }

/* ---------- Grids de acciones / premios ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.tile {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: 0 2px 10px rgba(0,0,0,0.06);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tile__image {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #eef1f5;
}

.tile__placeholder {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  background: linear-gradient(135deg, #dbeafe, #eef1f5);
  color: var(--blue);
  font-weight: 800;
}

.tile__body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.tile__name { font-weight: 700; font-size: 0.9rem; }
.tile__meta { font-size: 0.78rem; color: var(--text-muted); }

.tile--disabled { opacity: 0.5; }

/* ---------- Insignias de moneda ---------- */

.coin-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
}
.coin-badge.silver { background: #eef1f5; color: var(--silver-dark); }
.coin-badge.gold { background: #fff4dd; color: var(--gold-dark); }

.wallet-big {
  display: flex;
  gap: 12px;
  margin: 8px 0 18px;
}
.wallet-big .coin-badge { font-size: 1.1rem; padding: 10px 18px; }

/* ---------- Botón mala conducta ---------- */

.bad-behavior-card {
  margin-top: 18px;
  background: #fef2f2;
  border: 1px dashed var(--red);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.bad-behavior-card p { margin: 0 0 10px; font-size: 0.85rem; color: var(--text-muted); }

.bad-behavior-trigger { text-align: center; }

.face-btn {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  border: none;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 35% 30%, #fca5a5, #dc2626 65%, #7f1d1d);
  box-shadow:
    0 6px 14px rgba(220,38,38,0.35),
    inset -5px -5px 9px rgba(0,0,0,0.25),
    inset 5px 5px 9px rgba(255,255,255,0.35);
  transition: transform .15s ease;
}
.face-btn:active { transform: scale(0.94); }
.face-btn .sad-face-svg { width: 58%; height: 58%; }

.face-btn__label {
  margin-top: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}

.sad-face-svg { width: 68%; height: 68%; display: block; }

/* ---------- Confirmación inline ---------- */

.confirm-inline {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.confirm-inline .btn { flex: 1; }

/* ---------- Progreso semanal ---------- */

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #eef1f5;
  overflow: hidden;
  margin: 6px 0;
}
.progress-bar__fill {
  height: 100%;
  background: var(--gold);
  border-radius: 999px;
  transition: width .4s ease;
}

/* ---------- Premio especial ---------- */

.special-card { margin-top: 20px; }
.special-frame {
  position: relative;
  width: 100%;
  max-width: 260px;
  margin: 10px auto;
  aspect-ratio: 1;
  border-radius: var(--radius);
  overflow: hidden;
  background: #eef1f5;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.special-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.special-img--gray { filter: grayscale(100%); }
.special-img--color {
  clip-path: inset(0 calc(100% - (var(--progress, 0) * 100%)) 0 0);
  transition: clip-path .6s ease;
}
.special-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 12px;
}
.special-points {
  text-align: center;
  font-weight: 700;
  margin-top: 6px;
}
.special-ready {
  text-align: center;
  background: #ecfdf5;
  color: var(--green);
  border-radius: 10px;
  padding: 10px;
  margin-top: 10px;
  font-weight: 700;
}

/* ---------- Config ---------- */

.config-list { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.config-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border-radius: 12px;
  padding: 10px;
  box-shadow: 0 1px 6px rgba(0,0,0,0.05);
}
.config-row__thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: #eef1f5; flex-shrink: 0; }
.config-row__thumb.img-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #dbeafe, #eef1f5);
  color: var(--blue);
  font-weight: 800;
  font-size: 1.1rem;
}
.config-row__info { flex: 1; min-width: 0; }
.config-row__name { font-weight: 700; font-size: 0.9rem; }
.config-row__meta { font-size: 0.78rem; color: var(--text-muted); }
.config-row__actions { display: flex; gap: 6px; }
.config-row--inactive { opacity: 0.5; }

.form-card { margin-top: 16px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.checkbox-row input { width: 18px; height: 18px; }

.icon-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
  gap: 8px;
}
.icon-option {
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 4px;
  background: #eef1f5;
  cursor: pointer;
  line-height: 0;
}
.icon-option img { width: 100%; aspect-ratio: 1; border-radius: 8px; }
.icon-option--selected { border-color: var(--blue); background: #dbeafe; }

.section-title { font-size: 1.1rem; font-weight: 800; margin: 4px 0 4px; }
.section-sub { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 8px; }

.toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 50;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.toast--error { background: var(--red); }
.toast--success { background: var(--green); }

/* ---------- Monedas dibujadas ---------- */

.coin-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.coin {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
  box-shadow: inset -2px -2px 3px rgba(0,0,0,0.25), inset 2px 2px 2px rgba(255,255,255,0.55);
}
.coin--silver { background: radial-gradient(circle at 35% 30%, #f1f5f9, #94a3b8 70%, #64748b); }
.coin--gold { background: radial-gradient(circle at 35% 30%, #fff3c4, #f5b93d 70%, #d99a1c); }
.coin--red { background: radial-gradient(circle at 35% 30%, #fca5a5, #dc2626 70%, #991b1b); }
.coin-extra { font-size: 0.75rem; font-weight: 700; color: var(--text-muted); align-self: center; }
.coin-tray__empty { font-size: 0.78rem; color: var(--text-muted); }

.wallet-mini .coin-tray { gap: 2px; }
.wallet-mini .coin { width: 15px; height: 15px; font-size: 8px; }

.wallet-trays { display: flex; gap: 18px; margin: 10px 0 18px; flex-wrap: wrap; }
.wallet-trays__group { min-width: 110px; }
.wallet-trays__label { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
.wallet-trays .coin { width: 30px; height: 30px; font-size: 15px; }

/* ---------- Animación de "mala conducta" ---------- */

.penalty-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 60px;
  margin-top: 6px;
}
.penalty-scene .coin { width: 46px; height: 46px; font-size: 22px; }
.penalty-scene .coin--red { animation: coinDrop .5s ease-out; }
.penalty-scene .coin--victim {
  animation: coinShake .4s ease-in-out .5s, coinPop .35s ease-in forwards .9s;
}

@keyframes coinDrop {
  0% { transform: translateY(-60px) scale(0.4) rotate(-15deg); opacity: 0; }
  55% { transform: translateY(4px) scale(1.15) rotate(6deg); opacity: 1; }
  75% { transform: translateY(-4px) scale(0.95) rotate(-3deg); }
  100% { transform: translateY(0) scale(1) rotate(0deg); }
}
@keyframes coinShake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-8deg); }
  40% { transform: translateX(5px) rotate(6deg); }
  60% { transform: translateX(-4px) rotate(-4deg); }
  80% { transform: translateX(3px) rotate(3deg); }
}
@keyframes coinPop {
  0% { transform: scale(1) rotate(0); opacity: 1; }
  100% { transform: scale(0) rotate(25deg); opacity: 0; }
}

/* ---------- Carnet ---------- */

.carnet {
  max-width: 320px;
  margin: 20px auto;
  background: #fff;
  border-radius: 18px;
  padding: 24px;
  text-align: center;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  border: 2px dashed var(--gold);
}
.carnet h2 { margin: 0 0 4px; }
.carnet p { color: var(--text-muted); margin: 0 0 16px; }
.carnet .qr-holder { display: flex; justify-content: center; margin-bottom: 16px; }

@media print {
  .app-header, .no-print { display: none !important; }
  .app-main { padding: 0; }
  .carnet { box-shadow: none; margin: 0 auto; }
}
