/* Amigo invisible — mobile-first, una columna, modo oscuro automático. */

:root {
  --bg: #fff8f3;
  --surface: #ffffff;
  --surface-2: #fbeee6;
  --text: #2a1d1f;
  --muted: #6b5a5c;
  --border: #ead8cf;
  --primary: #b3261e;
  --primary-hover: #95201a;
  --on-primary: #ffffff;
  --accent: #1f6f4a;
  --accent-bg: #e3f3ea;
  --warn-bg: #fff3d6;
  --warn-text: #6b4a00;
  --danger: #b3261e;
  --focus: #1a5fd0;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 20 20 / 8%), 0 4px 16px rgb(60 20 20 / 6%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1416;
    --surface: #2a1f22;
    --surface-2: #33262a;
    --text: #f6ecee;
    --muted: #bfaeb1;
    --border: #47363a;
    --primary: #ef6b5f;
    --primary-hover: #f48a80;
    --on-primary: #230807;
    --accent: #7fd6a8;
    --accent-bg: #1d3328;
    --warn-bg: #3a2e12;
    --warn-text: #f3d68a;
    --danger: #ff8a80;
    --focus: #8ab4ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
    color-scheme: dark;
  }
}

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

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-x: hidden;
}

body.has-modal { overflow: hidden; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  outline: none;
}

.view { display: flex; flex-direction: column; gap: 16px; }

h1, h2, h3 { line-height: 1.2; margin: 0; overflow-wrap: anywhere; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; overflow-wrap: anywhere; }
a { color: var(--primary); }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.center { text-align: center; }
.muted { color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row > .btn { flex: 1 1 auto; }
.row-between { justify-content: space-between; }
.row-between > .btn { flex: 0 0 auto; }
.section { display: flex; flex-direction: column; gap: 12px; }

.eyebrow { color: var(--muted); font-size: .9rem; font-weight: 600; }
.lead { color: var(--muted); font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .9rem; }
.hint-error, .form-error { color: var(--danger); font-weight: 600; }
.form-error:empty { display: none; }
.big-text { font-size: 1.15rem; font-weight: 700; }
.big-emoji { font-size: 2.6rem; line-height: 1; }

/* ---------- Cabeceras */
.hero { text-align: center; padding: 24px 0 8px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.hero-small { padding-top: 8px; }
.hero-emoji { font-size: 3.5rem; line-height: 1; }
.group-header { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.meta { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); }
.note { color: var(--muted); white-space: pre-wrap; }
.back { align-self: flex-start; text-decoration: none; font-weight: 600; min-height: 48px; display: inline-flex; align-items: center; }

/* ---------- Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border: 2px solid transparent; border-radius: 12px;
  font: inherit; font-weight: 700; text-decoration: none; text-align: center;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, transform .1s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-danger { background: var(--danger); color: var(--on-primary); }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.1rem; }
.btn-small { min-height: 48px; padding: 6px 12px; font-size: .95rem; align-self: flex-start; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ""; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-icon {
  min-width: 48px; min-height: 48px; border: 0; border-radius: 12px;
  background: transparent; color: var(--muted); font: inherit; font-size: 1.2rem; cursor: pointer;
}
.btn-icon:hover { background: var(--surface-2); }
.btn-icon .icon-svg { display: block; width: 24px; height: 24px; margin: 0 auto; fill: currentColor; }

.link-btn {
  background: none; border: 0; padding: 12px 8px; min-height: 48px;
  color: var(--primary); font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer;
}

/* Acción principal fija abajo, al alcance del pulgar */
.bottom-bar {
  position: sticky; bottom: 0; z-index: 5;
  margin: 8px -16px calc(-24px - env(safe-area-inset-bottom));
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 30%);
}

/* ---------- Formularios */
.field { display: flex; flex-direction: column; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
label, legend { font-weight: 600; padding: 0; }
input, textarea, select {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; font-size: 16px; /* evita el zoom de iOS */
  color: var(--text); background: var(--surface);
  border: 2px solid var(--border); border-radius: 12px;
}
textarea { resize: vertical; min-height: 120px; }
input:focus, textarea:focus { border-color: var(--focus); outline: none; }
input.invalid { border-color: var(--danger); }
input:disabled { opacity: .6; }
.pin { font-size: 1.6rem; letter-spacing: .5em; text-align: center; max-width: 220px; }
.counter { color: var(--muted); font-size: .9rem; }

details.more, details.history { border: 2px solid var(--border); border-radius: 12px; background: var(--surface); }
details > summary { min-height: 48px; padding: 12px 14px; cursor: pointer; font-weight: 600; color: var(--primary); }
details.more > .stack { padding: 0 14px 14px; }

.people { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; counter-reset: p; }
.person { display: flex; gap: 6px; align-items: center; }
.person::before { counter-increment: p; content: counter(p); min-width: 1.6em; color: var(--muted); text-align: right; font-size: .9rem; }

.add-form { flex-wrap: nowrap; }
.add-form input { flex: 1 1 auto; }
.add-form .btn { flex: 0 0 auto; }

/* ---------- Tarjetas y listas */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px;
}
.card-private { border: 2px dashed var(--primary); }
.card-success { background: var(--accent-bg); border-color: var(--accent); text-align: center; }
.card-waiting { align-items: center; text-align: center; }
.notice { background: var(--warn-bg); color: var(--warn-text); padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.notice a { color: inherit; }
.warning { background: var(--warn-bg); color: var(--warn-text); padding: 10px 12px; border-radius: 10px; font-weight: 700; margin-top: 12px; }

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list-item {
  display: flex; align-items: center; gap: 10px; min-height: 56px; padding: 8px 8px 8px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text); text-decoration: none;
}
.list-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.list-main { font-weight: 700; overflow-wrap: anywhere; }
.list-sub { color: var(--muted); font-size: .9rem; }
.st-claimed { color: var(--accent); font-weight: 600; }
.st-revealed { color: var(--accent); font-weight: 700; }
.chevron { color: var(--muted); font-size: 1.5rem; padding-right: 6px; }
.badge, .tag, .chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.badge { background: var(--primary); color: var(--on-primary); }
.tag { background: var(--surface-2); color: var(--muted); }
.chip-open { background: var(--warn-bg); color: var(--warn-text); }
.chip-drawn { background: var(--accent-bg); color: var(--accent); }
.status-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-weight: 600; }

.names { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.name-btn {
  width: 100%; min-height: 60px; padding: 12px 16px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  background: var(--surface); color: var(--text); border: 2px solid var(--border); border-radius: 14px;
  font: inherit; font-size: 1.15rem; font-weight: 700; text-align: left; cursor: pointer;
}
.name-btn:hover:not(:disabled) { border-color: var(--primary); }
.name-btn:disabled { opacity: .55; cursor: not-allowed; }

.link-box { display: flex; flex-direction: column; gap: 8px; }
.link-input { font-size: 14px; color: var(--muted); background: var(--surface-2); }
.copy-area { min-height: 90px; font-size: 16px; }

/* El QR va siempre en blanco y negro (aunque el tema sea oscuro) para que se lea bien. */
.qr-wrap { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.qr-box { width: min(100%, 280px); background: #fff; border-radius: 12px; overflow: hidden; line-height: 0; }
.qr-box svg { display: block; width: 100%; height: auto; }

/* ---------- Listas de deseos */
.wishlist { display: flex; flex-direction: column; gap: 10px; }
.wish-current { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 12px; padding: 12px 14px; }
.wish-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.wish-meta { color: var(--muted); font-size: .85rem; margin-top: 6px; }
.history-list { margin: 0; padding: 0 14px 14px 32px; display: flex; flex-direction: column; gap: 12px; }
.history-list .wish-meta { margin: 0 0 2px; }

/* ---------- Tarjeta para destapar */
.reveal {
  display: block; width: 100%; height: 200px; padding: 0; border: 0; background: none;
  perspective: 1000px; cursor: pointer; font: inherit; color: inherit;
}
.reveal-inner {
  position: relative; display: block; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform .7s cubic-bezier(.2, .8, .2, 1);
}
.reveal.is-revealed { cursor: default; }
.reveal.is-revealed .reveal-inner { transform: rotateY(180deg); }
.reveal-face {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  padding: 16px; border-radius: 18px; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: var(--shadow); font-size: 1.1rem; font-weight: 700; text-align: center;
}
.reveal-front {
  isolation: isolate;
  color: #fff;
  background: repeating-linear-gradient(45deg, #b3261e 0 18px, #c4362c 18px 36px);
}
.reveal-front::after {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 22px; transform: translateX(-50%);
  background: #f2c14e; opacity: .85; z-index: -1;
}
.reveal-front > span:last-child { background: rgb(60 0 0 / 55%); padding: 6px 14px; border-radius: 999px; }
.reveal-back { background: var(--accent-bg); border: 2px solid var(--accent); transform: rotateY(180deg); }
.reveal-label { color: var(--muted); font-size: 1rem; }
.reveal-name { font-size: 2rem; color: var(--accent); overflow-wrap: anywhere; }

/* ---------- Pie */
.footer { border-top: 1px solid var(--border); margin-top: 16px; padding-top: 20px; display: flex; flex-direction: column; gap: 12px; }

/* ---------- Estados vacíos */
.empty { text-align: center; display: flex; flex-direction: column; gap: 14px; align-items: center; padding: 40px 0; }
.empty-emoji { font-size: 3rem; line-height: 1; }

/* ---------- Toasts */
.toasts {
  position: fixed; left: 0; right: 0; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 100;
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 16px; pointer-events: none;
}
.toast {
  max-width: 448px; width: 100%; padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow);
  animation: toast-in .2s ease-out; transition: opacity .3s;
}
.toast-error { background: var(--danger); color: var(--on-primary); }
.toast-success { background: var(--accent); color: var(--bg); }
.toast-out { opacity: 0; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* ---------- Diálogos */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 50%);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.modal {
  width: 100%; max-width: 448px; max-height: calc(100dvh - 32px); overflow-y: auto;
  background: var(--surface); color: var(--text); border-radius: 18px; padding: 20px;
  box-shadow: 0 10px 40px rgb(0 0 0 / 30%); animation: toast-in .2s ease-out;
}
.modal-title { margin-bottom: 12px; }
.modal-form > div:first-child p + p { margin-top: 8px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.modal-actions .btn { flex: 1 1 120px; }
.modal-actions .btn-block { flex-basis: 100%; }
@media (min-width: 520px) { .modal-backdrop { align-items: center; } }

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

/* ---------- Selector de fecha (día / mes / año) */
.date-select { display: grid; grid-template-columns: 1fr 2fr 1.3fr; gap: 8px; }
select { appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
select:focus { border-color: var(--focus); outline: none; }

/* ---------- Cuentas */
/* Campo trampa del registro: fuera de la pantalla (no display:none, que algunos bots detectan). */
.hp { position: absolute; left: -10000px; top: auto; width: 1px; height: 1px; overflow: hidden; }
.check { display: flex; align-items: center; gap: 10px; min-height: 48px; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--primary); }
.tag-me { margin-left: 8px; background: var(--primary); color: var(--on-primary); vertical-align: middle; }
.danger-link { color: var(--danger, var(--primary)); align-self: center; }
