/* Dividir la cuenta — papel / recibo, mobile-first */
:root {
  --bg: #f4efe6;
  --bg-elev: #fffdf8;
  --card: #fffdf8;
  --line: rgba(60, 40, 20, 0.12);
  --text: #2a241c;
  --muted: #7a6f62;
  --accent: #3d4f6f;
  --accent-ink: #f7f3eb;
  --wa: #25d366;
  --wa-ink: #053318;
  --ink-blue: #1e5bb8;
  --danger: #b33a2e;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "Source Sans 3", system-ui, -apple-system, sans-serif;
  --hand: "Kalam", cursive;
  --shadow: 0 6px 24px rgba(40, 30, 15, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100dvh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: calc(20px + var(--safe-t)) 20px calc(24px + var(--safe-b));
  max-width: 430px;
  margin: 0 auto;
  width: 100%;
}

/* —— Landing —— */
.screen-landing {
  justify-content: space-between;
  gap: 28px;
}

.landing-hero {
  margin-top: 10vh;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.landing-hero h1 {
  margin: 0 0 12px;
  font-size: clamp(1.85rem, 7vw, 2.25rem);
  line-height: 1.18;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--text);
}

.lede {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.45;
  max-width: 28ch;
}

.cta-stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: auto;
}

.cta-primary,
.cta-wa {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  border: none;
  border-radius: 12px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  padding: 14px 18px;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.cta-primary:active,
.cta-wa:active {
  transform: scale(0.98);
}

.cta-primary {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
}

.cta-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.link-quiet {
  background: none;
  border: none;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 8px;
  margin: 0 auto;
  display: block;
}

.link-quiet:active {
  color: var(--text);
}

/* —— Setup —— */
.screen-setup {
  padding-left: 16px;
  padding-right: 16px;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
}

.topbar-mid {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
}

.spacer {
  width: 40px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 1.15rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.ocr-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(61, 79, 111, 0.35);
  animation: pulse 1.4s ease infinite;
}

.ocr-dot.done {
  animation: none;
  background: var(--muted);
  box-shadow: none;
}

.ocr-dot.err {
  animation: none;
  background: var(--danger);
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(61, 79, 111, 0.35);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(61, 79, 111, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(61, 79, 111, 0);
  }
}

.thumb-row {
  display: flex;
  justify-content: center;
}

.thumb-row img {
  height: 96px;
  width: auto;
  max-width: 42%;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #e8e0d4;
  box-shadow: var(--shadow);
}

.setup-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  box-shadow: var(--shadow);
}

.setup-card h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #ebe4d8;
  border-radius: 10px;
}

.mode-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.mode-btn.active {
  background: var(--bg-elev);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(40, 30, 15, 0.08);
}

.hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip {
  min-width: 44px;
  height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
}

.chip.active {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.step-btn {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.step-val {
  font-size: 1.75rem;
  font-weight: 700;
  min-width: 2ch;
  text-align: center;
}

#namesArea {
  width: 100%;
  resize: vertical;
  min-height: 96px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  line-height: 1.4;
}

#namesArea:focus {
  outline: 2px solid rgba(61, 79, 111, 0.35);
  outline-offset: 1px;
}

.name-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  min-height: 8px;
}

.name-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 0.92rem;
  font-weight: 500;
}

.name-chip button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  font-size: 0.88rem;
  color: var(--muted);
  font-weight: 500;
}

.field-label em {
  font-style: normal;
  opacity: 0.75;
}

.field input[type="text"],
.money-input {
  width: 100%;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  padding: 12px 14px;
}

.field input[type="text"]:focus,
.money-input:focus-within {
  outline: 2px solid rgba(61, 79, 111, 0.35);
  outline-offset: 1px;
}

.money-input {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 14px;
}

.money-input span {
  color: var(--muted);
  font-weight: 600;
}

.money-input input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.15rem;
  font-weight: 600;
  min-height: 48px;
  padding: 0;
  outline: none;
  width: 100%;
}

/* —— Result —— */
.screen-result {
  padding: calc(12px + var(--safe-t)) 0 calc(12px + var(--safe-b));
  max-width: 430px;
}

.screen-result .topbar {
  padding: 0 12px;
}

.result-stage {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8px 12px 16px;
  -webkit-overflow-scrolling: touch;
}

.receipt-frame {
  position: relative;
  width: 100%;
  max-width: 380px;
  line-height: 0;
  border-radius: 6px;
  overflow: visible;
  box-shadow: var(--shadow);
  background: #f8f6f0;
}

.receipt-frame img {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.receipt-frame.has-ink-pad {
  background: #f8f6f0;
}

.ink-pad {
  width: 100%;
  background: #f8f6f0;
  flex-shrink: 0;
}

.overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hand-note {
  position: absolute;
  transform: translate(-50%, -50%) rotate(var(--rot, -3deg));
  font-family: var(--hand);
  color: var(--ink-blue);
  text-align: center;
  line-height: 1.15;
  pointer-events: none;
  filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.35)) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
  white-space: nowrap;
  font-size: clamp(1.15rem, 4.8vw, 1.55rem);
  font-weight: 700;
}

.hand-note.anchor-top {
  transform: translate(-50%, 0) rotate(var(--rot, -3deg));
}

.hand-note .line {
  display: inline-block;
  font-size: inherit;
  font-weight: 700;
}

.hand-note .line .amt {
  text-decoration: underline;
  text-decoration-thickness: 1.5px;
  text-underline-offset: 3px;
  margin-left: 0.28em;
}

.hand-note.each {
  white-space: nowrap;
  max-width: 92%;
  font-size: clamp(1.3rem, 5.4vw, 1.8rem);
}

.hand-note.each .line {
  display: inline-block;
}

.result-bar {
  padding: 10px 16px calc(8px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, transparent, var(--bg) 18%);
}

.result-summary {
  margin: 0;
  text-align: center;
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.35;
}

.cta-wa {
  background: var(--wa);
  color: var(--wa-ink);
  min-height: 54px;
  font-size: 1.1rem;
}

.cta-wa:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* —— Dialog / toast —— */
.sheet {
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  background: var(--bg-elev);
  color: var(--text);
  padding: 20px 18px calc(20px + var(--safe-b));
  margin: auto 0 0;
  width: min(100%, 430px);
  max-width: 100%;
}

.sheet::backdrop {
  background: rgba(40, 30, 15, 0.35);
}

.sheet h2 {
  margin: 0 0 14px;
  font-size: 1.15rem;
}

.sheet label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 14px;
}

.sheet input {
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 1.1rem;
  padding: 10px 14px;
}

.sheet menu {
  margin: 0;
  padding: 0;
  display: flex;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%) translateY(120%);
  background: #2a241c;
  color: #f7f3eb;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  max-width: min(90vw, 360px);
  text-align: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
  box-shadow: 0 8px 28px rgba(40, 30, 15, 0.25);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

@media (min-width: 480px) {
  body {
    background: #e8e0d4;
  }

  .screen {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    background: var(--bg);
  }
}
