/* Comxow/COMXOW, creada por A. Gavina Costero  2026, albertobicho@gmail.com */
/*
 * Librerías y código de terceros utilizados en este proyecto:
 *
 * - omggif (GIF encoder/decoder)
 *     Autor: Dean McNamee <dean@gmail.com>
 *     Licencia: MIT
 *     https://github.com/deanm/omggif
 *
 * - pako (compresión zlib/gzip)
 *     Autores: Andrei Tuputcyn, Vitaly Puzrin y colaboradores (Nodeca project)
 *     Licencia: MIT
 *     https://github.com/nodeca/pako
 *
 * - UPNG.js (codificador/decodificador PNG)
 *     Autor: Ivan Kutskir
 *     Licencia: MIT
 *     https://github.com/photopea/UPNG.js
 *
 * - LZW decompression (puerto JavaScript de implementación Java)
 *     Referencia original: https://gist.github.com/devunwired/4479231
 *     Licencia: dominio público / uso libre
 *
 * - Trix (editor de texto enriquecido)
 *     Autor: 37signals, LLC (Basecamp) — Javan Makhmali y Sam Stephenson
 *     Licencia: MIT
 *     https://trix-editor.org/  ·  https://github.com/basecamp/trix
 */
/* ============================================================
   ComXow - main.css
   Variables globales, reset, componentes compartidos
   ============================================================ */

:root {
  color-scheme: only light;
  /* Paleta cómic */
  --yellow:   #FFE135;
  --black:    #1A1A1A;
  --white:    #FFFFFF;
  --red:      #E8132A;
  --blue:     #0046CC;
  --violet:   #9B6BD9;
  --ink:      #2C1810;
  --paper:    #FFF9F0;
  /* Escala de grises — antes solo existían 100/300/500/700, dejando
     50/200/400/600/800 sin definir (var() sin fallback = valor inválido =
     borde/fondo/texto invisible). Añadidos interpolando entre los tonos
     ya existentes para mantener la misma progresión cálida. */
  --gray-50:  #FAF6EF;
  --gray-100: #F5F0E8;
  --gray-200: #DFD8CC;
  --gray-300: #C8C0B0;
  --gray-400: #A9A090;
  --gray-500: #8A8070;
  --gray-600: #6A6358;
  --gray-700: #4A4540;
  --gray-800: #2A2828;
  --shadow:   rgba(26,26,26,0.18);

  /* Tipografía */
  --font-display: Arial, Helvetica, sans-serif;
  --font-comic:   'Comic Neue', cursive;
  --font-body:    'Nunito', sans-serif;

  /* Layout */
  --header-h: 64px;
  --max-w: 1200px;
  --radius: 12px;
  --radius-sm: 6px;

  /* Sombras estilo viñeta */
  --box-shadow: 3px 3px 0px var(--black);
  --box-shadow-lg: 5px 5px 0px var(--black);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  scroll-behavior: smooth;
  height: 100%;          /* necesario para que editor-page height:100% funcione */
  background: var(--paper);
}
body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  height: 100%;          /* propaga la altura al appView del editor */
  min-height: 100dvh;    /* páginas normales ocupan toda la pantalla */
  line-height: 1.5;
  overflow-x: hidden;
}
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }

/* ── BOTONES ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.95rem;
  border-radius: var(--radius-sm);
  border: 2.5px solid var(--black);
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
  box-shadow: var(--box-shadow);
  white-space: nowrap;
  text-align: center;
  user-select: none;
}
.btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--black); }
.btn-primary  { background: var(--yellow); color: var(--black); }
.btn-outline  { background: var(--white);  color: var(--black); }
.btn-danger   { background: var(--red);    color: var(--white); }
.btn-blue     { background: var(--blue);   color: var(--white); }
.btn-ghost    { background: transparent; border-color: transparent; box-shadow: none; color: var(--gray-700); }
.btn-ghost:hover { background: var(--gray-100); }

.btn-hero {
  background: var(--red);
  color: var(--white);
  font-size: 1.2rem;
  padding: 14px 36px;
  box-shadow: var(--box-shadow-lg);
  border-radius: var(--radius);
}
.btn-hero:hover { transform: translate(-2px,-2px); box-shadow: 7px 7px 0 var(--black); }

/* ── HEADER ── */
.site-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  background: linear-gradient(to right, var(--yellow) 33%, #fff8cc 50%, var(--yellow) 67%);
  border-bottom: 3px solid var(--black);
  height: auto;
  min-height: var(--header-h);
  box-shadow: 0 3px 0 var(--black);
}
.header-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  height: 100%;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.logo-link { display: flex; flex-direction: column; }
.logo-main {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 2rem;
  letter-spacing: 2px;
  line-height: 1;
  color: var(--black);
}
.logo-accent { color: var(--red); }
.logo-big { font-size: 1.25em; line-height: 1; }
.logo-sub {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--gray-700);
  letter-spacing: 0.5px;
  display: none;
}
@media(min-width:600px){ .logo-sub { display: block; } }

/* Hamburger */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}
.hamburger span {
  display: block;
  width: 24px; height: 3px;
  background: var(--black);
  border-radius: 2px;
  transition: all .2s;
}
.hamburger.open span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

@media(max-width:600px){
  .hamburger { display: flex; }
  .main-nav {
    display: none;
    position: absolute;
    top: var(--header-h);
    left: 0; right: 0;
    background: var(--yellow);
    border-bottom: 3px solid var(--black);
    padding: 16px 20px;
    flex-direction: column;
    gap: 10px;
  }
  .main-nav.open { display: flex; }
}

.main-nav { display: flex; align-items: center; gap: 10px; }
.nav-user  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nav-username { font-weight: 700; font-size: 0.9rem; }

/* ── DROPDOWN ── */
.dropdown { position: relative; }
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--white);
  border: 2.5px solid var(--black);
  border-radius: var(--radius-sm);
  box-shadow: none;
  min-width: 160px;
  z-index: 1000;
  overflow: visible;
}
.dropdown-menu::after {
  content: '';
  position: absolute;
  left: -12px; right: -12px;
  top: 100%;
  height: 16px;
  background: linear-gradient(to bottom, rgba(0,0,0,0.22), transparent);
  -webkit-mask-image: linear-gradient(to right, transparent 0%, black 20%, black 80%, transparent 100%);
  mask-image: linear-gradient(to right, transparent 0%, black 20%, black 80%, transparent 100%);
  pointer-events: none;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: block;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background .12s;
  border-bottom: 1px solid var(--gray-100);
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--yellow); }

.btn-avatar {
  background: var(--black);
  color: var(--yellow);
  width: 38px; height: 38px;
  border-radius: 50%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 900;
  font-size: 0.95rem;
  box-shadow: var(--box-shadow);
}

/* ── FOOTER ── */
.site-footer {
  text-align: center;
  padding: 24px;
  border-top: 2.5px solid var(--black);
  font-size: 0.85rem;
  color: var(--gray-500);
  background: var(--gray-100);
  margin-top: 60px;
}

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: var(--black);
  color: var(--yellow);
  padding: 12px 28px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: var(--box-shadow-lg);
  z-index: 9999;
  transition: opacity .25s, visibility .25s;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
}
.toast.show { opacity: 1; visibility: visible; }

/* ── FORMULARIOS ── */
.form-group { margin-bottom: 18px; }
.form-label {
  display: block;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--ink);
}
.form-input {
  width: 100%;
  padding: 11px 14px;
  border: 2.5px solid var(--black);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 1rem;
  background: var(--white);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
  box-shadow: var(--box-shadow);
}
.form-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 3px 3px 0 var(--blue);
}
.form-error {
  display: none;
  color: var(--red);
  font-size: 0.82rem;
  font-weight: 700;
  margin-top: 4px;
}
.form-error.visible { display: block; }

/* ── MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 5000;
  align-items: flex-start;   /* top en mobile, no tapa el teclado */
  justify-content: center;
  padding: env(safe-area-inset-top, 0px) 16px 16px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
/* En pantallas grandes volver a centrar */
@media (min-height: 700px) and (min-width: 600px) {
  .modal-overlay { align-items: center; padding: 20px; }
}
.modal-box {
  background: var(--white);
  border: 3px solid var(--black);
  border-radius: var(--radius);
  box-shadow: var(--box-shadow-lg);
  max-width: 480px;
  width: 100%;
  overflow: hidden;
}
.modal-header {
  background: var(--yellow);
  border-bottom: 2.5px solid var(--black);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title { font-family: var(--font-display); font-weight: 700; font-size: 1.4rem; letter-spacing: 1px; }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.4rem; line-height: 1; color: var(--black);
}
.modal-body { padding: 24px 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1.5px solid var(--gray-100);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── UTILS ── */
.hidden   { display: none !important; }
.sr-only  { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── SCROLLBAR CUSTOM ── */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--black); border-radius: 4px; }

/* ── RESPONSIVE MOBILE FULL SCREEN ── */
@media(max-width:600px){
  :root { --header-h: 56px; }
  .btn { padding: 9px 16px; font-size: 0.88rem; }
  .header-inner { padding: 0 10px; gap: 8px; }
  .logo-main { font-size: 1.5rem; }
}

/* ── PWA safe area ── */
@supports(padding: max(0px)){
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* ══════════════════════════════════════════
   Cabecera global (inyectada por header.js)
   ══════════════════════════════════════════ */
.home-header { height: auto; }
/* Fila 1: logo + usuario (tagline centrado debajo del logo, en posición absoluta, sin afectar al alto)  |  Fila 2: botón FS */
.home-header-inner {
  display: flex;
  flex-direction: column;
  padding: 6px 14px 6px;
}
.home-header-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.home-logo-area {
  display: flex; align-items: center;
  flex-shrink: 0;
  position: relative;
  top: 8px;
  align-self: flex-start;
}
.home-logo-area .logo-main { font-size: 1.8rem; line-height: 1; }
.logo-img-link { display: flex; align-items: center; }
.logo-img {
  height: 26px;
  width: auto;
  display: block;
}
.home-tagline {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 2px;
  font-size: 0.72rem; font-weight: 700;
  color: var(--gray-600);
  line-height: 1.3;
  white-space: normal;
  text-align: center;
  width: max-content;
  max-width: 200px;
  pointer-events: none;
}
.home-user-area { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.home-guest     { display: flex; align-items: center; gap: 5px; font-size: 0.78rem; font-weight: 700; white-space: nowrap; }
.home-logged    { display: flex; align-items: center; gap: 8px; }
.home-user-link {
  color: var(--ink); text-decoration: none;
  font-size: 0.78rem; font-weight: 700;
  background: none; border: none; cursor: pointer;
  padding: 0; font-family: var(--font-body);
  max-width: 110px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.home-user-link:hover { text-decoration: underline; }
.home-user-sep  { color: var(--gray-300); font-size: 0.7rem; }
.home-dots-btn  {
  background: none; border: none; font-size: 1.3rem;
  cursor: pointer; color: var(--gray-700);
  padding: 2px 4px; line-height: 1; flex-shrink: 0;
}
.home-dots-btn:hover { color: var(--black); }
.dropdown-divider       { height: 1px; background: var(--gray-100); margin: 4px 0; }
.dropdown-section-label {
  display: block;
  padding: 6px 14px 2px;
  font-size: 0.68rem; font-weight: 900;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--gray-400); pointer-events: none;
}
.danger-item         { color: var(--red) !important; }
.disabled-item       { color: var(--gray-300) !important; pointer-events: none; cursor: default; }
.dropdown-menu-right { left: auto !important; right: 0; }

/* ══ COMPENSACIÓN CABECERA FIJA ══
   Cada tipo de página empuja su contenido principal
   exactamente la altura necesaria para no quedar tapado.
   El editor y el reader tienen su propia lógica.        */

/* Login, registro: solo cabecera fija */
body.auth-page { padding-top: 0; }

/* Editor: cabecera fija, el resto lo gestiona editor.css */
body.editor-page { padding-top: 0; }

/* ══ BANNER DE INSTALACIÓN PWA ══ */
.install-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 9999;
  background: var(--black);
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -2px 16px rgba(0,0,0,.3);
  transform: translateY(100%);
  transition: transform .35s cubic-bezier(0.4, 0, 0.2, 1);
}
.install-banner.visible { transform: translateY(0); }

.install-banner-icon {
  font-size: 2rem; flex-shrink: 0;
}
.install-banner-text {
  flex: 1;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
}
.install-banner-text strong {
  display: block;
  font-size: 0.95rem;
  font-weight: 900;
  margin-bottom: 2px;
  color: var(--yellow);
}
.install-banner-actions {
  display: flex; flex-direction: column; gap: 6px; flex-shrink: 0;
}
.install-btn {
  padding: 7px 14px;
  font-family: var(--font-body); font-weight: 900; font-size: 0.82rem;
  border: none; border-radius: 4px; cursor: pointer;
  white-space: nowrap;
}
.install-btn-ok {
  background: var(--yellow); color: var(--black);
}
.install-btn-ok:hover { background: #ffd700; }
.install-btn-dismiss {
  background: transparent; color: var(--gray-400);
  font-size: 0.75rem; font-weight: 600; text-align: center;
}
.install-btn-dismiss:hover { color: var(--white); }


/* Fila 2: botón FS a la derecha (el tagline pasó a fila 1, bajo el logo) */
.home-header-row2 {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-top: 2px;
  min-height: 20px;
}
.hdr-sys-btns {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.hdr-sys-btn {
  background: none;
  border: 1.5px solid rgba(0,0,0,.35);
  border-radius: 4px;
  color: var(--black);
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font-body);
  padding: 1px 6px;
  cursor: pointer;
  line-height: 1.6;
  transition: background .12s, opacity .12s;
  white-space: nowrap;
  opacity: .65;
  flex-shrink: 0;
}
.hdr-sys-btn:hover  { opacity: 1; background: rgba(0,0,0,.06); }
.hdr-sys-btn:hover  { background: rgba(0,0,0,.07); }
.hdr-sys-btn:active { background: rgba(0,0,0,.14); }
.hdr-sys-btn[aria-pressed="true"] {
  background: var(--black);
  color: var(--yellow);
}
.hdr-open-app-btn {
  background: var(--black);
  color: var(--yellow);
  border-color: var(--black);
}
.hdr-open-app-btn:hover { background: var(--gray-700); }

/* ── BOTÓN PANTALLA COMPLETA EN ROW2 ── */
.hdr-fs-row2-btn {
  background: none;
  border: 1.5px solid rgba(0,0,0,.30);
  border-radius: 4px;
  color: var(--gray-600);
  font-size: 0.68rem;
  font-weight: 700;
  font-family: var(--font-body);
  padding: 1px 7px 1px 6px;
  cursor: pointer;
  line-height: 1.7;
  transition: background .12s, opacity .12s, color .12s;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 4px;
}
.hdr-fs-row2-btn:hover  { background: rgba(0,0,0,.06); color: var(--black); }
.hdr-fs-row2-btn:active { background: rgba(0,0,0,.12); }
.hdr-fs-row2-btn[aria-pressed="true"] {
  background: var(--black); color: var(--yellow); border-color: var(--black);
}
/* Texto largo: visible si hay espacio (>320px disponibles aprox) */
.hdr-fs-label-long  { display: none; }
.hdr-fs-label-short { display: inline; }
@media (min-width: 400px) {
  .hdr-fs-label-long  { display: inline; }
  .hdr-fs-label-short { display: none; }
}
/* Sin texto si la pantalla es muy pequeña */
@media (max-width: 299px) {
  .hdr-fs-label-short { display: none; }
}

/* ── BOTÓN PANTALLA COMPLETA (solo PWA) ── */
.fullscreen-prompt {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: var(--paper);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  font-family: var(--font-body);
}
.fullscreen-prompt.visible { display: flex; }
.fullscreen-prompt .fp-logo {
  font-size: 3rem; font-family: var(--font-display);
  font-weight: 900; letter-spacing: -1px;
}
.fullscreen-prompt .fp-logo span { color: var(--red); }
.fullscreen-prompt .fp-btn {
  background: var(--black); color: var(--yellow);
  border: none; border-radius: 6px;
  padding: 14px 32px;
  font-family: var(--font-body); font-weight: 900; font-size: 1rem;
  cursor: pointer; letter-spacing: .02em;
}
.fullscreen-prompt .fp-skip {
  font-size: 0.75rem; color: var(--gray-600);
  background: none; border: none; cursor: pointer;
  font-family: var(--font-body);
}

/* ── TOAST "APP INSTALADA" ── */
.installed-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--black);
  color: var(--white);
  padding: 12px 22px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: 10000;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  max-width: calc(100vw - 32px);
  text-align: center;
  white-space: normal;
}
.installed-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ══════════════════════════════════════════
   INPUTS: evitar zoom automático en iOS (font-size ≥ 16px)
   y garantizar tamaño táctil cómodo en Android
   ══════════════════════════════════════════ */
.form-input,
.mc-field input, .mc-field select,
.ed-modal-field input, .ed-modal-field select,
.auth-form input, .auth-form select {
  font-size: 16px !important;  /* ≥16px previene autozoom en iOS Safari */
  min-height: 44px;            /* mínimo táctil recomendado por Google/Apple */
  -webkit-text-size-adjust: 100%;
}

/* Teclado virtual: cuando el viewport se encoge por el teclado,
   los modales ya están en top, pero también aseguramos que los
   formularios son scrollables */
.mc-modal-box,
.ed-modal-sheet,
.modal-box,
.auth-card {
  max-height: 92dvh;   /* dvh = dynamic viewport height, se actualiza con el teclado */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Fallback para navegadores sin dvh */
@supports not (max-height: 1dvh) {
  .mc-modal-box,
  .ed-modal-sheet,
  .modal-box,
  .auth-card {
    max-height: 92vh;
  }
}


/* ── MODAL READER EMBED (compartido: expositor + admin) ── */
.reader-modal {
  position: fixed; inset: 0; z-index: 9000;
  background: #000;
  display: flex; align-items: center; justify-content: center;
}
.reader-modal.hidden { display: none; }
.reader-modal-inner {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}
.reader-modal-frame {
  width: 100%; height: 100%;
  border: none; display: block;
}
.reader-modal-close {
  position: absolute; top: 10px; right: 10px; z-index: 10;
  background: rgba(0,0,0,.7); border: 1px solid rgba(255,255,255,.2);
  color: #fff; border-radius: 50%; width: 34px; height: 34px;
  font-size: 1rem; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: background .15s;
}
.reader-modal-close:hover { background: rgba(180,0,0,.8); }
