:root {
  --fondo: #f4f5f9;
  --superficie: #ffffff;
  --texto: #1b1d26;
  --tenue: #5d6172;
  --linea: #dfe2ea;
  --acento: #33479c;
  --acento-suave: #e6e9f6;
  --sobre-acento: #ffffff;
  --ok: #1d7f4e;
  --ok-suave: #e3f3ea;
  --alerta: #9a5b00;
  --alerta-suave: #fdf1dc;
  --error: #b3261e;
  --error-suave: #fbe7e5;
  --visor: #24262f;
  --radio: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #111218;
    --superficie: #1b1d26;
    --texto: #eceef5;
    --tenue: #a3a7b8;
    --linea: #2e313d;
    --acento: #8c9df0;
    --acento-suave: #262c4a;
    --sobre-acento: #10132a;
    --ok: #5fd09a;
    --ok-suave: #173326;
    --alerta: #f0b453;
    --alerta-suave: #3a2c12;
    --error: #ff8a80;
    --error-suave: #3d1c1a;
    --visor: #07080b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fondo: #111218; --superficie: #1b1d26; --texto: #eceef5; --tenue: #a3a7b8; --linea: #2e313d;
  --acento: #8c9df0; --acento-suave: #262c4a; --sobre-acento: #10132a; --ok: #5fd09a; --ok-suave: #173326;
  --alerta: #f0b453; --alerta-suave: #3a2c12; --error: #ff8a80; --error-suave: #3d1c1a; --visor: #07080b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
}
#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.vista { flex: 1; display: flex; flex-direction: column; gap: 18px; }
.vista[hidden] { display: none; }
.centro { justify-content: center; text-align: center; align-items: center; }
.centro > p { max-width: 34ch; margin: 0; color: var(--tenue); }

h1, h2 { margin: 0; line-height: 1.15; text-wrap: balance; }
h1 { font-size: clamp(28px, 8vw, 38px); letter-spacing: -0.02em; }
h2 { font-size: 24px; letter-spacing: -0.01em; }
.cabeza { padding-top: 8px; }
.cabeza.compacta { padding-top: 0; }
.kicker { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--acento); }
.bienvenida, .sub { margin: 8px 0 0; color: var(--tenue); }
.sub { margin-top: 4px; font-size: 15px; }

.cupo {
  display: flex; align-items: center; gap: 16px;
  background: var(--superficie);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  padding: 18px 20px;
}
.cupo-num {
  font-size: 44px; font-weight: 700; line-height: 1; color: var(--acento);
  min-width: 1.2em; text-align: center; font-variant-numeric: tabular-nums;
}
.cupo-num.infinito { font-size: 46px; }
.cupo-txt { color: var(--tenue); font-size: 15px; }
.cupo-txt b { display: block; color: var(--texto); font-size: 17px; }
.cupo.agotado .cupo-num { color: var(--error); }

.aviso {
  margin: 0; padding: 12px 14px; border-radius: 10px;
  background: var(--alerta-suave); color: var(--alerta); font-size: 15px;
}
.aviso.suave { font-size: 14px; }
.aviso.error { background: var(--error-suave); color: var(--error); }

.acciones { display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 56px; padding: 12px 18px;
  border-radius: var(--radio); border: 1.5px solid var(--linea);
  background: var(--superficie); color: var(--texto);
  font: inherit; font-size: 17px; font-weight: 600;
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, background-color .15s ease, opacity .15s ease;
}
.btn svg { width: 24px; height: 24px; flex: none; }
.btn:active { transform: scale(.98); }
.btn.primario { background: var(--acento); border-color: var(--acento); color: var(--sobre-acento); }
.btn.texto { border-color: transparent; background: transparent; color: var(--tenue); min-height: 48px; }
.btn[aria-disabled="true"], .btn:disabled { opacity: .45; pointer-events: none; }
.btn:focus-visible, .chip:focus-visible { outline: 3px solid var(--acento); outline-offset: 2px; }
.oculto { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.codigo { margin: 0; text-align: center; color: var(--tenue); font-size: 14px; }
.codigo b { color: var(--texto); font-size: 17px; letter-spacing: .04em; }

/* Visor de recorte */
.visor {
  background: var(--visor);
  border-radius: var(--radio);
  padding: 14px;
  display: flex; align-items: center; justify-content: center;
  min-height: 200px;
}
#lienzo {
  display: block; touch-action: none; cursor: grab;
  box-shadow: 0 0 0 1px rgba(255,255,255,.25), 0 6px 24px rgba(0,0,0,.45);
  background: #fff;
}
#lienzo:active { cursor: grabbing; }
.ayuda { margin: -8px 0 0; text-align: center; font-size: 13px; color: var(--tenue); }

.herramientas { display: flex; flex-direction: column; gap: 12px; }
.zoom { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--tenue); }
.zoom input { flex: 1; accent-color: var(--acento); height: 28px; }
.fila { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  flex: 1 1 0; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 10px;
  border-radius: 999px; border: 1.5px solid var(--linea);
  background: var(--superficie); color: var(--texto);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  -webkit-tap-highlight-color: transparent; white-space: nowrap;
}
.chip svg { width: 18px; height: 18px; flex: none; }
.chip[aria-pressed="true"] { background: var(--acento-suave); border-color: var(--acento); color: var(--acento); }
.chip:disabled { opacity: .4; }

/* Envío */
.anillo {
  width: 64px; height: 64px; border-radius: 50%;
  border: 5px solid var(--acento-suave); border-top-color: var(--acento);
  animation: girar 0.9s linear infinite;
}
@keyframes girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .anillo { animation-duration: 3s; } }
.barra { width: min(320px, 100%); height: 8px; border-radius: 99px; background: var(--acento-suave); overflow: hidden; }
.barra > div { height: 100%; width: 0; background: var(--acento); transition: width .2s ease; }

.sello { width: 76px; height: 76px; border-radius: 50%; display: grid; place-items: center; }
.sello svg { width: 40px; height: 40px; }
.sello.ok { background: var(--ok-suave); color: var(--ok); }
.sello.error { background: var(--error-suave); color: var(--error); }
.destacado { color: var(--texto) !important; font-weight: 600; font-size: 17px; }
.centro .acciones { width: 100%; margin-top: 12px; }

.pie { margin-top: 18px; text-align: center; font-size: 12px; color: var(--tenue); letter-spacing: .06em; }
