:root {
  --bg: #e4eaf0;
  --card: #ffffff;
  --ink: #142433;
  --muted: #555555;
  --border: #cccccc;
  --ok: #1a7a3a;
  --ok-bg: #d8f5e2;
  --fail: #b01a1a;
  --fail-bg: #fde0e0;
  --btn: #1a3a5c;
  --spin: #333;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  height: 100%;
  overflow: hidden;
}
.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100dvh;
}
header.bar {
  flex: 0 0 auto;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.55rem 0.9rem;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
}
header.bar h1 { margin: 0; font-size: 1.15rem; letter-spacing: 0.02em; }
header.bar .tag { color: var(--muted); font-size: 0.78rem; }
.sheet-area {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.45rem 0.55rem 0.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
#preview {
  background: #fff;
  border: 1px solid #bbb;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  width: 100%;
  height: 100%;
  max-height: 100%;
  aspect-ratio: 297 / 210;
  max-width: min(100%, calc((100dvh - 210px) * 297 / 210));
}
#preview svg { display: block; width: 100%; height: 100%; }
.controls {
  flex: 0 0 auto;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding: 0.55rem 0.7rem 0.7rem;
  padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
}
.row-gen { display: flex; gap: 0.55rem; margin-bottom: 0.5rem; }
button#btn-generar {
  flex: 1;
  cursor: pointer;
  border: 2px solid #000;
  border-radius: 14px;
  padding: 0.95rem 1rem;
  font-size: 1.35rem;
  font-weight: 700;
  background: var(--btn);
  color: #fff;
  letter-spacing: 0.01em;
}
button#btn-generar:active { opacity: 0.88; transform: scale(0.99); }
button#btn-generar:disabled { opacity: 0.55; cursor: wait; }
.row-caps {
  display: flex;
  gap: 0.55rem;
  margin-bottom: 0.45rem;
}
.cap {
  flex: 1;
  cursor: pointer;
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 0.72rem 0.8rem;
  font-size: 1.15rem;
  font-weight: 700;
  text-align: center;
}
.cap:disabled { opacity: 0.4; cursor: default; }
.cap.bien {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok);
}
.cap.falla {
  background: var(--fail-bg);
  color: var(--fail);
  border-color: var(--fail);
}
.cap:active:not(:disabled) { transform: scale(0.98); opacity: 0.9; }
.status {
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.4;
  min-height: 2.6em;
}
.status strong { color: var(--ink); font-weight: 600; }
.status .ok { color: var(--ok); }
.status .bad { color: var(--fail); }
.flash {
  position: fixed;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.82);
  color: #fff;
  padding: 0.85rem 1.4rem;
  border-radius: 12px;
  font-size: 1.25rem;
  font-weight: 700;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 40;
}
.flash.show { opacity: 1; }
.spinner-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 5;
  border-radius: 0;
}
.sheet-area { position: relative; }
.spinner-overlay.on { display: flex; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid #ddd;
  border-top-color: var(--spin);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media print {
  header.bar, .controls, .flash, .spinner-overlay { display: none !important; }
  .app { display: block; height: auto; overflow: visible; }
  .sheet-area { padding: 0; }
  #preview {
    border: none; box-shadow: none;
    width: 297mm; height: 210mm;
    max-width: none; max-height: none;
  }
  @page { size: A4 landscape; margin: 0; }
}
