:root {
  --night: #0a0b2e;
  --violet: #2a1670;
  --violet-2: #4b1fa8;
  --neon: #c8ff00;
  --neon-ink: #142000;
  --cyan: #00e0ff;
  --red: #e30613;
  --red-dark: #a3000e;
  --yellow: #ffd400;
  --paper: #fffdf6;
  --ink: #0a0b2e;
  --muted: rgba(255, 255, 255, .62);
  --line: rgba(255, 255, 255, .12);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --display: "Anton", "Impact", "Arial Narrow Bold", sans-serif;
  --cond: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--night);
  color: #fff;
  font-family: var(--cond);
  font-weight: 600;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }

/* Fondo estilo Hypermotion: degradado violeta + barridos de luz */
.bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(0, 224, 255, .28), transparent 60%),
    radial-gradient(90% 55% at 0% 100%, rgba(200, 255, 0, .20), transparent 60%),
    linear-gradient(165deg, var(--violet-2) 0%, var(--violet) 38%, var(--night) 78%);
}
.bg::before, .bg::after {
  content: ""; position: absolute; left: -30%; width: 160%; height: 90px;
  transform: rotate(-24deg);
  background: linear-gradient(90deg, transparent, rgba(200, 255, 0, .16), transparent);
}
.bg::before { top: 22%; }
.bg::after { top: 62%; height: 46px; background: linear-gradient(90deg, transparent, rgba(0, 224, 255, .14), transparent); }

.app {
  min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(var(--safe-t) + 10px) 20px calc(var(--safe-b) + 16px);
  max-width: 480px; margin: 0 auto;
}

/* Cabecera */
.top { display: flex; align-items: center; gap: 12px; position: relative; }
.badge {
  flex: none; width: 54px; height: 54px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--yellow) 0 50%, var(--red) 50% 100%);
  color: #fff; font-family: var(--display); font-size: 16px; letter-spacing: 0; white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0,0,0,.35);
  box-shadow: 0 6px 16px rgba(0,0,0,.35), inset 0 0 0 2px rgba(255,255,255,.85);
}
.badge span { color: var(--night); margin: 0 1px; text-shadow: none; }
.kicker {
  margin: 0; font-size: 13px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--neon);
}
h1 {
  margin: 0; font-family: var(--display); font-weight: 400; font-size: 34px; line-height: 1;
  text-transform: uppercase; letter-spacing: .5px;
}
h1 em { font-style: normal; color: var(--neon); }
.status {
  position: absolute; right: 0; top: 4px;
  font-size: 12px; padding: 4px 8px; border-radius: 99px;
  background: var(--red); text-transform: uppercase; letter-spacing: 1px;
}

/* Cromo */
.card-wrap { flex: 1; display: grid; place-items: center; padding: 18px 0 14px; perspective: 900px; }
.cromo {
  width: min(84vw, 320px); aspect-ratio: 5 / 6.6;
  padding: 10px; border-radius: 18px;
  background: var(--paper);
  box-shadow: 0 24px 48px rgba(0,0,0,.45), 0 0 0 1px rgba(0,0,0,.08);
  transform: rotate(-2deg);
  transition: transform .5s cubic-bezier(.2, .8, .2, 1.2);
}
.cromo.pop { animation: pop .6s cubic-bezier(.2, .8, .2, 1.3); }
@keyframes pop {
  0% { transform: rotate(-2deg) scale(1); }
  35% { transform: rotate(3deg) scale(1.06) rotateY(12deg); }
  100% { transform: rotate(-2deg) scale(1); }
}
.cromo-inner {
  position: relative; height: 100%; border-radius: 10px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center;
  background: linear-gradient(160deg, #3a1d9a 0%, #1b0f5c 45%, #0a0b2e 100%);
}
.stripes {
  position: absolute; inset: -20%;
  background: repeating-linear-gradient(-28deg, transparent 0 34px, rgba(200, 255, 0, .10) 34px 40px, transparent 40px 70px, rgba(0, 224, 255, .08) 70px 74px);
}
.holo {
  position: absolute; inset: 0; mix-blend-mode: screen; opacity: .55;
  background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,.35) 45%, rgba(0,224,255,.25) 50%, rgba(200,255,0,.25) 55%, transparent 70%);
  background-size: 250% 100%;
  animation: shine 5s ease-in-out infinite;
}
@keyframes shine { 0%, 100% { background-position: 120% 0; } 50% { background-position: -20% 0; } }
.cromo-label {
  position: relative; margin: 22px 0 0; padding: 4px 12px;
  font-weight: 800; font-size: 15px; letter-spacing: 2.4px; text-transform: uppercase;
  color: var(--neon-ink); background: var(--neon);
  transform: skewX(-10deg);
}
.count {
  position: relative; flex: 1; display: grid; place-items: center;
  font-family: var(--display); font-size: clamp(120px, 44vw, 190px); line-height: 1;
  color: #fff; font-variant-numeric: tabular-nums;
  text-shadow: 4px 4px 0 var(--red), 8px 8px 0 rgba(0,0,0,.35);
}
.count.long { font-size: clamp(90px, 32vw, 140px); }
.plate {
  position: relative; width: 100%; display: flex; align-items: stretch;
  background: var(--red); color: #fff; min-height: 52px;
  border-top: 4px solid var(--yellow);
}
.plate-num {
  display: grid; place-items: center; padding: 0 12px;
  background: var(--yellow); color: var(--red-dark);
  font-family: var(--display); font-size: 20px;
}
.plate-text {
  flex: 1; display: flex; align-items: center; padding: 0 12px;
  font-weight: 800; font-style: italic; font-size: 19px; text-transform: uppercase; letter-spacing: .5px;
}

/* Botones */
.actions { display: grid; grid-template-columns: 1.35fr 1fr; gap: 12px; }
.btn {
  position: relative; height: 64px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 800; font-size: 21px; text-transform: uppercase; letter-spacing: .6px;
  transition: transform .12s, filter .12s;
}
.btn:active { transform: translateY(2px) scale(.98); filter: brightness(.92); }
.btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.btn .lock { width: 16px; height: 16px; stroke-width: 2.4; opacity: .7; }
.btn-add { background: var(--neon); color: var(--neon-ink); box-shadow: 0 5px 0 #7fa300, 0 10px 24px rgba(200, 255, 0, .25); }
.btn-sub { background: var(--red); color: #fff; box-shadow: 0 5px 0 var(--red-dark), 0 10px 24px rgba(227, 6, 19, .3); }
.btn-ghost { background: rgba(10, 11, 46, .08); color: var(--ink); }
.btn[disabled] { opacity: .5; pointer-events: none; }

/* Historial */
.history { margin-top: 20px; }
.history h2 {
  margin: 0 0 6px; font-size: 13px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.history ul { list-style: none; margin: 0; padding: 0; }
.history li {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--line); font-size: 17px;
}
.history li:last-child { border-bottom: 0; }
.history li.empty { color: var(--muted); }
.history .tag {
  flex: none; min-width: 44px; text-align: center; padding: 2px 8px; border-radius: 8px;
  font-family: var(--display); font-size: 16px;
}
.history .tag.add { background: var(--neon); color: var(--neon-ink); }
.history .tag.subtract { background: var(--red); }
.history .when { margin-left: auto; color: var(--muted); font-size: 15px; }

/* Popup (hoja inferior con forma de sobre) */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end;
  background: rgba(5, 5, 25, .6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  animation: fade .2s ease;
}
.sheet-backdrop[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.sheet {
  width: 100%; max-width: 480px; margin: 0 auto; color: var(--ink);
  animation: up .32s cubic-bezier(.2, .9, .3, 1.1);
}
@keyframes up { from { transform: translateY(100%); } }
.crimp {
  height: 14px;
  background:
    linear-gradient(135deg, transparent 50%, var(--paper) 50%) 0 0 / 14px 14px repeat-x,
    linear-gradient(225deg, transparent 50%, var(--paper) 50%) 0 0 / 14px 14px repeat-x;
}
.sheet-body {
  background: var(--paper);
  padding: 14px 22px calc(var(--safe-b) + 18px);
  background-image: linear-gradient(90deg, var(--red) 0 33%, var(--yellow) 33% 66%, var(--neon) 66%);
  background-size: 100% 6px; background-repeat: no-repeat;
}
.sheet h3 {
  margin: 12px 0 0; font-family: var(--display); font-weight: 400; font-size: 30px; text-transform: uppercase;
}
.sheet-sub { margin: 2px 0 14px; color: #4a4b6a; font-size: 17px; }
.stepper { display: flex; align-items: center; justify-content: center; gap: 22px; }
.step {
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--night); color: #fff; font-size: 32px; line-height: 1; font-weight: 800;
}
.step:active { transform: scale(.94); }
.amount {
  min-width: 110px; text-align: center; font-family: var(--display); font-size: 76px; line-height: 1;
  color: var(--ink); text-shadow: 3px 3px 0 var(--yellow);
}
.chips { display: flex; justify-content: center; gap: 8px; margin: 12px 0 16px; }
.chips button {
  min-width: 52px; height: 36px; padding: 0 10px; border-radius: 99px;
  background: rgba(10, 11, 46, .07); color: var(--ink); font-weight: 800; font-size: 18px;
}
.chips button.on { background: var(--night); color: var(--neon); }
.pw { display: block; }
.pw[hidden] { display: none; }
.pw span { display: block; font-size: 14px; letter-spacing: 1.4px; text-transform: uppercase; color: #4a4b6a; margin-bottom: 6px; }
.pw input {
  width: 100%; height: 54px; border-radius: 14px; padding: 0 16px;
  border: 2px solid rgba(10, 11, 46, .15); background: #fff; color: var(--ink);
  font: 600 20px var(--cond); /* >=16px: iOS no hace zoom */
  -webkit-user-select: text; user-select: text;
}
.pw input:focus { outline: none; border-color: var(--violet-2); box-shadow: 0 0 0 4px rgba(75, 31, 168, .15); }
.error { min-height: 22px; margin: 8px 0 4px; color: var(--red); font-size: 16px; font-weight: 800; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 50% { transform: translateX(8px); } 75% { transform: translateX(-4px); } }
.sheet-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.sheet-actions .btn { height: 58px; font-size: 20px; }

/* Toast */
.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 12px); z-index: 20;
  transform: translate(-50%, -140%); transition: transform .35s cubic-bezier(.2, .9, .3, 1.2);
  padding: 10px 18px; border-radius: 99px; background: var(--paper); color: var(--ink);
  font-weight: 800; font-size: 17px; box-shadow: 0 10px 30px rgba(0,0,0,.35); white-space: nowrap;
}
.toast.show { transform: translate(-50%, 0); }

/* Confeti de mini-cromos */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 15; overflow: hidden; }
.confetti i {
  position: absolute; top: -30px; width: 14px; height: 18px; border-radius: 3px;
  border: 2px solid #fff; animation: fall 1.4s cubic-bezier(.3, .6, .5, 1) forwards;
}
@keyframes fall { to { transform: translate(var(--dx), 110vh) rotate(var(--r)); opacity: .9; } }

@media (max-height: 700px) {
  .history { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Liquidar pendientes */
.settle {
  width: 100%; margin: 0 0 6px; padding: 12px 16px; border-radius: 16px;
  display: flex; flex-direction: column; align-items: flex-start; text-align: left;
  background: repeating-linear-gradient(-45deg, var(--yellow) 0 14px, #ffe14d 14px 28px);
  color: var(--ink); border: 2px dashed var(--red-dark);
}
.settle[hidden] { display: none; }
.settle-main { font-family: var(--display); font-size: 22px; text-transform: uppercase; letter-spacing: .4px; }
.settle-sub { font-size: 16px; font-weight: 800; color: #5a3b00; }
.settle.confirm { background: var(--red); color: #fff; border-color: #fff; }
.settle.confirm .settle-sub { color: #ffe1e1; }
.history .tag.settle { background: var(--yellow); color: var(--ink); }
