/* ============ MuffDex · estilos ============ */
:root {
  --bg: #FFF7EA;
  --bg-2: #FFEFD6;
  --card: #FFFFFF;
  --ink: #2B2340;
  --ink-2: #6B6380;
  --line: #EADFCB;
  --accent: #FF6B4A;
  --accent-ink: #FFFFFF;
  --accent-soft: #FFE1D8;
  --violet: #6C5CE7;
  --ok: #1F9D6B;
  --danger: #D64545;
  --r-comun: #7FA392;
  --r-raro: #3D8BFD;
  --r-epico: #A259FF;
  --r-legendario: #F0A500;
  --radius: 18px;
  --shadow: 0 2px 0 rgba(43, 35, 64, .08), 0 8px 24px rgba(43, 35, 64, .06);
  --font-display: 'Fredoka', ui-rounded, system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { overflow-x: clip; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
a { color: var(--violet); }
code { background: var(--bg-2); padding: .1em .35em; border-radius: 6px; font-size: .9em; }
[hidden] { display: none !important; }

/* ---------- Botones e inputs ---------- */
button, .btn {
  font: inherit; font-weight: 700; cursor: pointer; border: 0; border-radius: 14px;
  padding: .8em 1.2em; background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 3px 0 rgba(0,0,0,.15); transition: transform .08s, filter .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: .4em; text-decoration: none;
}
button:active, .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.15); }
button:disabled { opacity: .55; cursor: default; }
button.secondary, .btn.secondary { background: var(--card); color: var(--ink); border: 2px solid var(--line); box-shadow: none; }
button.ghost { background: transparent; color: var(--ink-2); box-shadow: none; padding: .5em .7em; }
button.danger { background: var(--danger); }
button.small { padding: .45em .8em; font-size: .88rem; border-radius: 10px; }
button.block { width: 100%; }

label { display: block; font-weight: 700; font-size: .9rem; margin: .9em 0 .35em; }
input, select, textarea {
  font: inherit; width: 100%; padding: .75em .9em; border-radius: 12px;
  border: 2px solid var(--line); background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--violet); }
textarea { resize: vertical; min-height: 70px; }
.hint { font-size: .82rem; color: var(--ink-2); margin-top: .3em; }
.hint.ok { color: var(--ok); } .hint.bad { color: var(--danger); }
.error-box { background: #FDE8E8; color: #9B2C2C; border-radius: 12px; padding: .7em .9em; margin-top: 1em; font-size: .92rem; }

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

/* ---------- Layout ---------- */
.screen { min-height: 100vh; min-height: 100dvh; }
.center-screen { display: grid; place-items: center; padding: 24px 16px; }
.setup { max-width: 440px; }

.spinner { width: 42px; height: 42px; border-radius: 50%; border: 5px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth ---------- */
.auth-wrap { width: 100%; max-width: 400px; }
.brand { text-align: center; margin-bottom: 1.2rem; }
.brand img { width: 92px; height: 92px; animation: bob 2.6s ease-in-out infinite; }
.brand h1 { font-size: 2.3rem; margin: .2em 0 .1em; color: var(--ink); }
.brand p { color: var(--ink-2); margin: 0; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
.pending-banner { background: var(--violet); color: #fff; border-radius: 14px; padding: .8em 1em; margin-bottom: 1rem; font-weight: 700; text-align: center; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg-2); border-radius: 14px; padding: 4px; margin-bottom: .4rem; }
.tabs button { background: transparent; color: var(--ink-2); box-shadow: none; padding: .6em; border-radius: 11px; }
.tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.06); }
.linkish { background: none; border: 0; box-shadow: none; color: var(--violet); padding: .4em 0; font-weight: 700; font-size: .9rem; }

/* ---------- App principal ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: rgba(255, 247, 234, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { display: flex; align-items: center; gap: 8px; font-family: var(--font-display); font-weight: 600; font-size: 1.3rem; }
.topbar .logo img { width: 32px; height: 32px; }
.topbar .spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: .35em; background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: .3em .75em; font-weight: 800; font-size: .88rem; white-space: nowrap; }
.chip.accent { background: var(--accent-soft); border-color: transparent; color: #B4381E; }

main.views { max-width: 720px; margin: 0 auto; padding: 16px 16px 110px; }
.view-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 6px 0 12px; }
.view-title h2 { margin: 0; }

.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr);
  background: #fff; border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav button {
  background: none; box-shadow: none; color: var(--ink-2); flex-direction: column; gap: 2px; padding: .4em; font-size: .78rem; border-radius: 12px;
}
.bottomnav button .ico { font-size: 1.35rem; line-height: 1; }
.bottomnav button.active { color: var(--ink); background: var(--bg-2); }

/* Stats del álbum */
.stats { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(0,1fr) minmax(0,1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.stat .k { font-size: .75rem; color: var(--ink-2); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; }
.progress { height: 10px; background: var(--bg-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #FFB443); border-radius: 99px; transition: width .6s; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.filters button { flex: none; background: var(--card); color: var(--ink-2); border: 2px solid var(--line); box-shadow: none; padding: .4em .9em; border-radius: 99px; font-size: .88rem; }
.filters button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Cuadrícula de Muffs */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.mcard {
  position: relative; background: var(--card); border-radius: 16px; padding: 8px 8px 10px; text-align: center;
  box-shadow: var(--shadow); border: 3px solid transparent; cursor: pointer; color: var(--ink);
  display: block; width: 100%; min-width: 0; font-weight: 400;
}
.mcard:active { transform: scale(.97); }
.mcard .num { position: absolute; top: 6px; left: 8px; font-size: .72rem; font-weight: 800; color: var(--ink-2); }
.mcard .imgbox { aspect-ratio: 1; display: grid; place-items: center; background: var(--bg); border-radius: 12px; margin-bottom: 6px; overflow: hidden; }
.mcard img { width: 86%; height: 86%; object-fit: contain; }
.mcard .nm { font-weight: 800; font-size: .84rem; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.mcard.locked .nm { color: var(--ink-2); letter-spacing: .1em; }
.mcard .tag { position: absolute; top: 6px; right: 6px; font-size: .7rem; }
.silhouette { filter: brightness(0) opacity(.78); }
.mcard.locked .imgbox { background: repeating-linear-gradient(45deg, #F6EDDD, #F6EDDD 8px, #F2E6D2 8px, #F2E6D2 16px); }
.rdot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

.r-comun { --r: var(--r-comun); }
.r-raro { --r: var(--r-raro); }
.r-epico { --r: var(--r-epico); }
.r-legendario { --r: var(--r-legendario); }
.mcard.captured { border-color: var(--r); }
.mcard.captured.r-legendario { background: linear-gradient(160deg, #FFF6D6, #fff 60%); }
.rdot { background: var(--r); }
.rbadge { display: inline-block; background: var(--r); color: #fff; border-radius: 99px; padding: .15em .7em; font-size: .75rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }

.empty { text-align: center; color: var(--ink-2); padding: 40px 16px; }
.empty img { width: 90px; opacity: .7; }

/* Logros */
.ach-list { display: grid; gap: 10px; }
.ach { display: grid; grid-template-columns: 54px 1fr auto; gap: 12px; align-items: center; background: var(--card); border-radius: 16px; padding: 12px; box-shadow: var(--shadow); }
.ach .icon { width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center; font-size: 1.8rem; background: var(--accent-soft); }
.ach.locked .icon { background: var(--bg-2); filter: grayscale(1); opacity: .6; }
.ach .t { font-weight: 800; }
.ach .d { font-size: .86rem; color: var(--ink-2); }
.ach .progress { height: 7px; }
.ach .pts { font-weight: 800; font-size: .82rem; color: var(--ok); white-space: nowrap; }
.ach.locked .pts { color: var(--ink-2); }

/* Ranking */
.me-rank { display: flex; align-items: center; gap: 14px; background: var(--ink); color: #fff; border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; }
.me-rank .pos { font-family: var(--font-display); font-size: 2rem; font-weight: 600; }
.me-rank .lbl { font-size: .8rem; opacity: .75; }
.rank-list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.rank-row { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.rank-row:last-child { border-bottom: 0; }
.rank-row .p { font-family: var(--font-display); font-weight: 600; font-size: 1.1rem; text-align: center; }
.rank-row .u { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .s { font-size: .8rem; color: var(--ink-2); }
.rank-row .pt { font-weight: 800; }
.rank-row.me { background: var(--accent-soft); }

/* Modal de detalle */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(43, 35, 64, .55); display: grid; place-items: end center; padding: 0; }
@media (min-width: 560px) { .modal { place-items: center; padding: 16px; } }
.sheet { background: var(--card); width: 100%; max-width: 480px; border-radius: 24px 24px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: up .25s ease-out; }
@media (min-width: 560px) { .sheet { border-radius: 24px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.detail { text-align: center; }
.detail .big { width: 70%; max-width: 260px; aspect-ratio: 1; object-fit: contain; margin: 4px auto 10px; display: block; }
.detail .meta { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0; }
.detail .desc { color: var(--ink-2); }

/* ---------- Revelado de captura ---------- */
.reveal { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; padding: 20px 16px; overflow-x: hidden; overflow-y: auto;
  background: radial-gradient(circle at 50% 35%, #4A3D7A, #2B2340 70%); color: #fff; text-align: center; }
.reveal-inner { width: 100%; max-width: 420px; position: relative; margin: auto; }
.reveal .stage { position: relative; width: min(230px, 62vw); height: min(230px, 62vw); margin: 0 auto 8px; display: grid; place-items: center; }
.reveal .rays { position: absolute; inset: -40px; border-radius: 50%; opacity: 0;
  background: repeating-conic-gradient(from 0deg, rgba(255,255,255,.16) 0 10deg, transparent 10deg 20deg);
  animation: spin 14s linear infinite; transition: opacity .6s; }
.reveal.done .rays { opacity: 1; }
.reveal .stage img { width: 100%; height: 100%; object-fit: contain; position: relative; z-index: 2; transition: filter .7s ease, transform .5s; }
.reveal .stage img.silhouette { filter: brightness(0) invert(1) opacity(.25); animation: wobble .5s ease-in-out infinite; }
@keyframes wobble { 25% { transform: rotate(-5deg) scale(.97); } 75% { transform: rotate(5deg) scale(.97); } }
.reveal.done .stage img { animation: pop .55s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes pop { 0% { transform: scale(.6); } 100% { transform: scale(1); } }
.reveal h1 { font-size: 2rem; margin: .2em 0; }
.reveal .sub { opacity: .8; margin-bottom: 12px; }
.reveal .pill { display: inline-block; max-width: 100%; background: rgba(255,255,255,.14); border-radius: 99px; padding: .35em .9em; font-weight: 800; margin: 4px; }
.reveal .pill.gold { background: #F0A500; color: #2B2340; }
.reveal .new-ach { background: rgba(255,255,255,.1); border-radius: 16px; padding: 12px; margin: 14px 0 4px; text-align: left; }
.reveal .new-ach h3 { font-size: 1rem; margin-bottom: 8px; text-align: center; }
.reveal .new-ach .row { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.reveal .new-ach .row .i { font-size: 1.6rem; }
.reveal .actions { margin-top: 18px; display: grid; gap: 8px; }
.reveal .fade-in { animation: fadein .5s both; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } }
.confetti { position: absolute; inset: 0; pointer-events: none; z-index: 1; overflow: visible; }
.confetti i { position: absolute; top: 50%; left: 50%; width: 10px; height: 14px; border-radius: 3px; opacity: 0; animation: burst 1.1s ease-out forwards; }
@keyframes burst {
  0% { opacity: 1; transform: translate(-50%, -50%) rotate(0); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(var(--rot)); }
}

/* Toast */
#toast { position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: .7em 1.1em; border-radius: 14px; font-weight: 700; opacity: 0; transition: .25s; z-index: 100; max-width: calc(100% - 32px); text-align: center; pointer-events: none; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }
#toast.ok { background: var(--ok); }

/* ============ ADMIN ============ */
body.admin { background: #F6F3EE; }
.admin-wrap { max-width: 1100px; margin: 0 auto; padding: 16px 16px 60px; }
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; margin: 4px 0 18px; }
.admin-tabs button { background: transparent; color: var(--ink-2); box-shadow: none; border-radius: 12px; padding: .6em 1em; flex: none; }
.admin-tabs button.active { background: var(--ink); color: #fff; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input, .toolbar select { width: auto; flex: 1 1 160px; padding: .55em .8em; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .k { font-size: .75rem; color: var(--ink-2); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-family: var(--font-display); font-size: 1.7rem; font-weight: 600; }

.alist { display: grid; gap: 10px; }
.arow { background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 12px; display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: start; }
.arow.off { opacity: .6; }
.arow .thumb { width: 64px; height: 64px; border-radius: 12px; background: var(--bg); display: grid; place-items: center; overflow: hidden; font-size: 2rem; }
.arow .thumb img { width: 90%; height: 90%; object-fit: contain; }
.arow .title { font-weight: 800; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.arow .sub { font-size: .85rem; color: var(--ink-2); margin: 2px 0 8px; }
.arow .btns { display: flex; flex-wrap: wrap; gap: 6px; }
.nfc-link { display: flex; gap: 6px; align-items: center; background: var(--bg); border-radius: 10px; padding: 6px 8px; margin: 6px 0 8px; font-family: ui-monospace, Menlo, monospace; font-size: .8rem; word-break: break-all; }
.nfc-link span { flex: 1; }
.status-pill { font-size: .72rem; font-weight: 800; border-radius: 99px; padding: .15em .6em; background: #DDF5EA; color: var(--ok); }
.status-pill.off { background: #EEE; color: #777; }

.table-wrap { background: #fff; border-radius: 14px; box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); background: #FBF8F3; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: 0; }

dialog { border: 0; border-radius: 22px; padding: 0; width: min(560px, calc(100% - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(43, 35, 64, .5); }
dialog form { padding: 20px; max-height: 86vh; overflow: auto; }
dialog .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.img-pick { display: flex; gap: 12px; align-items: center; }
.img-pick .preview { width: 84px; height: 84px; border-radius: 14px; background: var(--bg); display: grid; place-items: center; overflow: hidden; flex: none; }
.img-pick .preview img { width: 90%; height: 90%; object-fit: contain; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-top: 14px; }
.check input { width: auto; }
.callout { background: #EEF0FF; border-radius: 14px; padding: 12px 14px; font-size: .9rem; margin-bottom: 14px; }
.success-box { text-align: center; }
.success-box .nfc-link { font-size: .95rem; padding: 10px 12px; }

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