:root {
  --bg: #0b0b10;
  --surface: #15151d;
  --surface-2: #1d1d28;
  --line: #2a2a38;
  --text: #f3f3f7;
  --muted: #9a9ab0;
  --cyan: #25f4ee;
  --pink: #fe2c55;
  --wa: #25d366;
  --wa-ink: #062b16;
  --chat: #0b141a;
  --radius: 18px;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Inter', system-ui, -apple-system, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Header + buscador (fijo arriba) ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(var(--bg) 70%, rgba(11, 11, 16, 0.85));
  backdrop-filter: blur(10px);
}
.top-row, .search, main { max-width: 1100px; margin-left: auto; margin-right: auto; }
.top-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.brand {
  display: flex; align-items: center; gap: 9px;
  font: 800 21px/1 var(--display); color: var(--text); text-decoration: none; letter-spacing: -0.02em;
}
.brand b { color: var(--cyan); text-shadow: 2px 2px 0 var(--pink); }
.logo {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), var(--pink)); color: #000; font-size: 18px;
}
.search {
  display: flex; gap: 6px; padding: 6px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--line);
}
.search:focus-within { border-color: var(--cyan); }
.search input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; padding: 10px 10px; font-size: 16px; }
.search input::placeholder { color: var(--muted); }

main { padding: 6px 16px 80px; }

/* ---------- Botones ---------- */
.primary, .ghost, .wa {
  border-radius: 14px; padding: 12px 18px; font-weight: 600; border: 1px solid transparent;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s; white-space: nowrap;
}
.primary:active, .ghost:active, .wa:active, .tile:active { transform: scale(0.96); }
.primary { background: var(--text); color: #000; }
.ghost { background: var(--surface-2); border-color: var(--line); }
.wa { background: var(--wa); color: var(--wa-ink); }
.small { padding: 8px 12px; font-size: 14px; border-radius: 12px; }
.link { background: none; border: 0; padding: 4px 0; color: var(--muted); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
button:disabled { opacity: 0.45; cursor: default; }
.count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 4px;
  border-radius: 99px; background: var(--pink); color: #fff; font-size: 12px;
}

/* ---------- Sticker del día ---------- */
.daily { margin: 4px 0 14px; }
.daily-card {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px; text-align: left;
  border-radius: 22px; border: 1px solid var(--line);
  background: radial-gradient(circle at 15% 50%, rgba(37, 244, 238, 0.14), transparent 55%), var(--chat);
}
.daily-card img { width: 108px; height: 108px; object-fit: contain; flex-shrink: 0; filter: drop-shadow(0 6px 14px rgba(0,0,0,.5)); }
.daily-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.daily-text small { color: var(--cyan); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; font-size: 11px; }
.daily-text strong { font: 600 15px/1.3 var(--body); }
.daily-cta { color: var(--wa); font-weight: 600; font-size: 14px; margin-top: 4px; }

/* ---------- Filtros ---------- */
.filters { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.seg { display: flex; padding: 4px; gap: 4px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 8px; border-radius: 10px; color: var(--muted); font-weight: 500; font-size: 14px; }
.seg button[aria-pressed='true'] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px #3a3a4c; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 6px 14px; color: var(--muted);
  font-size: 14px; white-space: nowrap;
}
.chips button[aria-pressed='true'] { background: var(--text); color: #000; border-color: var(--text); }

/* ---------- Muro de stickers (como en un chat) ---------- */
.wall {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 8px; border-radius: 22px;
  background: var(--chat) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='4' cy='4' r='1.2' fill='%23ffffff10'/%3E%3C/svg%3E");
}
.wall:empty { display: none; }
.tile {
  position: relative; aspect-ratio: 1; border: 0; padding: 6px 6px 22px; border-radius: 16px; background: transparent;
  display: flex; align-items: center; justify-content: center; transition: transform 0.1s, background 0.15s;
  animation: pop 0.35s ease both;
}
.tile:hover { background: rgba(255, 255, 255, 0.05); }
.tile img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 4px 10px rgba(0,0,0,.45)); }
.tile-label { position: absolute; left: 0; right: 0; bottom: 4px; font-size: 11px; color: #8696a0; text-align: center; }
.pos { position: absolute; top: 4px; left: 6px; font: 800 13px/1 var(--display); color: var(--cyan); z-index: 1; }
.tile.skeleton { animation: shimmer 1.2s infinite linear; background: linear-gradient(90deg, #111b21 0%, #1b262d 50%, #111b21 100%); background-size: 200% 100%; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.96); } }
@keyframes shimmer { to { background-position: -200% 0; } }

.empty-state { text-align: center; padding: 36px 18px; border-radius: 22px; background: var(--chat); color: var(--muted); }
.empty-state .big { font: 800 24px/1.1 var(--display); color: var(--text); margin: 0 0 8px; }
.empty-state p { margin: 0; }

.drop {
  display: block; margin-top: 14px; padding: 14px 16px; border-radius: 16px;
  border: 1.5px dashed var(--line); color: var(--muted); font-size: 14px; cursor: pointer; text-align: center;
}
.drop.over { border-color: var(--cyan); color: var(--text); }

.howto { margin-top: 14px; border-radius: 16px; background: var(--surface); border: 1px solid var(--line); padding: 4px 16px; }
.howto summary { cursor: pointer; padding: 10px 0; font-weight: 600; }
.tabs { display: flex; gap: 6px; margin: 4px 0 4px; }
.tabs button { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 6px 13px; color: var(--muted); font-size: 14px; }
.tabs button[aria-selected='true'] { background: var(--text); color: #000; border-color: var(--text); }
.tab-panel { color: var(--muted); padding-left: 20px; font-size: 15px; }
.tab-panel li { margin: 6px 0; }
.tab-panel b { color: var(--text); }
.tip { color: var(--muted); font-size: 14px; margin: 16px 4px 0; }
.tip b { color: var(--text); }

.status { color: var(--muted); min-height: 1.5em; }
.status.error { color: var(--pink); }

/* ---------- Resultados de un video ---------- */
.results-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.results-head p { color: var(--muted); margin: 0; font-size: 14px; }
.grid { columns: 4 220px; column-gap: 12px; }
.card {
  break-inside: avoid; margin: 0 0 12px; display: block; width: 100%; padding: 0; text-align: left;
  border-radius: var(--radius); overflow: hidden; background: var(--surface); border: 1px solid var(--line);
  animation: pop 0.35s ease both;
}
.card img { display: block; width: 100%; height: auto; background: var(--surface-2); }
.card .cap { padding: 8px 10px 10px; font-size: 12px; color: var(--muted); }
.card .cap b { color: var(--text); font-weight: 600; }
.card .cap p { margin: 3px 0 0; color: var(--text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.grid .skeleton { break-inside: avoid; margin: 0 0 12px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
.more { display: flex; justify-content: center; margin-top: 10px; }

/* ---------- Hojas (editor / colección) ---------- */
dialog.sheet {
  width: min(940px, 100vw - 24px); max-height: calc(100dvh - 24px); padding: 0; border: 1px solid var(--line);
  border-radius: 24px; background: var(--surface); color: var(--text); overflow: auto;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(6px); }
.sheet-inner { padding: 16px 18px 22px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font: 800 24px/1.1 var(--display); }
.sheet-stat { margin: 0; color: var(--muted); font-size: 14px; }
.icon { background: var(--surface-2); border: 1px solid var(--line); width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0; }

.editor { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 20px; }
.previews { display: flex; flex-direction: column; gap: 12px; }
.canvas-wrap { position: relative; border-radius: 18px; overflow: hidden; aspect-ratio: 1; touch-action: none; cursor: grab; }
.checker {
  background-color: #2b2b36;
  background-image:
    linear-gradient(45deg, #353542 25%, transparent 25%), linear-gradient(-45deg, #353542 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #353542 75%), linear-gradient(-45deg, transparent 75%, #353542 75%);
  background-size: 24px 24px; background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}
#canvas { display: block; width: 100%; height: 100%; }
.busy {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 10px;
  background: rgba(11, 11, 16, 0.72); text-align: center; padding: 20px;
}
.busy p { margin: 0; font-weight: 500; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--cyan); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chat {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding: 14px; border-radius: 18px;
  background: var(--chat) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='4' cy='4' r='1.2' fill='%23ffffff10'/%3E%3C/svg%3E");
}
.bubble { align-self: flex-start; background: #202c33; padding: 6px 10px; border-radius: 0 10px 10px 10px; font-size: 14px; }
.chat-sticker { width: 150px; height: 150px; object-fit: contain; }

.controls { display: flex; flex-direction: column; gap: 12px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.actions .wa { grid-column: 1 / -1; padding: 16px; font-size: 17px; }
.edit { border: 1px solid var(--line); border-radius: 16px; padding: 2px 14px 12px; }
.edit summary { cursor: pointer; padding: 10px 0; color: var(--muted); font-weight: 600; }
.edit[open] summary { color: var(--text); }
fieldset { border: 0; margin: 0 0 12px; padding: 0; }
legend { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; padding: 0; }
legend small { font-weight: 400; }
.edit .seg { background: var(--bg); }
input[type='range'] { width: 100%; accent-color: var(--cyan); }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.meta { font-size: 12px; color: var(--muted); margin: 0; font-variant-numeric: tabular-nums; }
.sheet-links { display: flex; justify-content: space-between; }

.collection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.mini { position: relative; border-radius: 14px; overflow: hidden; aspect-ratio: 1; }
.mini img { width: 100%; height: 100%; object-fit: contain; display: block; }
.mini-actions { position: absolute; inset: auto 6px 6px; display: flex; gap: 4px; justify-content: flex-end; }
.mini-actions button { border: 0; border-radius: 9px; padding: 5px 8px; font-size: 12px; background: rgba(0, 0, 0, 0.75); }
.empty { color: var(--muted); }
.pack { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.pack input, .nick input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 12px; outline: 0; }
.pack input:focus, .nick input:focus { border-color: var(--cyan); }
.nick { display: flex; flex-direction: column; gap: 6px; margin-top: 18px; font-size: 14px; }
.nick small { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: #000; padding: 10px 16px; border-radius: 99px; font-weight: 600; font-size: 14px;
  transition: opacity 0.2s, transform 0.2s; z-index: 10; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .wall { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding: 12px; }
  .filters { flex-direction: row; align-items: center; justify-content: space-between; }
  .filters .seg { width: 320px; }
}

@media (max-width: 719px) {
  .grid { columns: 2 140px; column-gap: 10px; }
  .card { margin-bottom: 10px; }
  .editor { grid-template-columns: 1fr; gap: 14px; }
  .chat { display: none; }
  dialog.sheet { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; border: 0; }
  .sheet-inner { padding-top: max(14px, env(safe-area-inset-top)); }
  .canvas-wrap { max-width: 78vw; margin: 0 auto; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
