/* comic.css — Sección del cómic pixel-art
   Marco, chrome, globos jagged, transiciones pixel dissolve.
   Sin frameworks. Sin fuentes externas. Sin emojis. */

:root {
  /* Paleta de la guía */
  --ink:        #1b1f2a;
  --blue:       #2f6fbf;
  --blue-deep:  #1c3f6e;
  --cream:      #f4ead5;
  --paper:      #e8dcc0;
  --white:      #fffdf7;
  --sky:        #8fc6e8;
  --grass:      #4e8a4a;

  /* Estado del comic */
  --corners: 6px;
  --border: 2px;
  --topbar-h: 56px;
  --navbar-h: 80px;

  /* Easing */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-quick: 140ms;
  --dur-base: 220ms;
  --dur-slow: 380ms;
}

/* Reset local */
.comic *, .comic *::before, .comic *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.comic {
  --ink-soft: rgba(27, 31, 42, 0.72);
  --ink-mute: rgba(27, 31, 42, 0.45);

  width: 100%;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #241d18 0%, #1a1611 60%, #0f0d0a 100%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-stretch: condensed;
  font-feature-settings: "ss01" on, "ss02" on;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  position: relative;
  isolation: isolate;
}

.comic *::selection { background: var(--blue); color: var(--white); }

/* Patrón pixel grid sutil de fondo */
.comic::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 8px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.025) 0 1px, transparent 1px 8px);
  z-index: 0;
  pointer-events: none;
}

/* ====== TOP BAR ====== */
.comic-topbar {
  position: relative;
  z-index: 5;
  height: var(--topbar-h);
  background:
    linear-gradient(180deg, var(--ink) 0%, #0f131c 100%);
  border-bottom: var(--border) solid var(--blue-deep);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  box-shadow: 0 4px 0 rgba(0,0,0,0.35);
}

.comic-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.comic-badge-icon {
  width: 40px; height: 40px;
  background: var(--blue);
  border: var(--border) solid var(--ink);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--white);
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.05em;
  box-shadow: 0 3px 0 var(--blue-deep);
}
.comic-badge-text {
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-weight: 700;
  color: var(--cream);
  font-size: 13px;
  letter-spacing: -0.02em;
  text-transform: uppercase;
  line-height: 1.1;
}
.comic-badge-text small {
  display: block;
  color: var(--sky);
  font-size: 9px;
  letter-spacing: 0.18em;
  font-weight: 600;
  margin-top: 2px;
  opacity: 0.8;
}

.comic-chapter-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}
.comic-chapter-info > div {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.comic-chapter-cap {
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-weight: 700;
  font-size: 13px;
  color: var(--sky);
  letter-spacing: 0.12em;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 2px 8px;
  border: 1px solid rgba(143, 198, 232, 0.4);
  border-radius: 3px;
}
.comic-chapter-titulo {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-stretch: condensed;
  font-weight: 700;
  font-size: 20px;
  color: var(--white);
  letter-spacing: -0.02em;
  text-transform: uppercase;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comic-chapter-zona {
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-size: 11px;
  color: rgba(244, 234, 213, 0.55);
  letter-spacing: 0.06em;
  margin-top: 2px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.comic-topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.comic-progress-counter {
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--cream);
  letter-spacing: 0.06em;
}
.comic-progress-counter strong {
  color: var(--sky);
  font-size: 16px;
}

.comic-cast-btn {
  height: 40px;
  padding: 0 16px;
  background: var(--paper);
  border: var(--border) solid var(--ink);
  border-radius: var(--corners);
  color: var(--ink);
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform var(--dur-quick) var(--ease-out), box-shadow var(--dur-quick) var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.comic-cast-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 0 var(--ink); }
.comic-cast-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* ====== STAGE ====== */
.comic-stage {
  position: relative;
  z-index: 2;
  height: calc(100vh - var(--topbar-h) - var(--navbar-h));
  padding: 24px clamp(16px, 4vw, 56px);
  display: grid;
  place-items: center;
}

.comic-frame-wrap {
  position: relative;
  width: 100%;
  max-width: 1280px;
  height: 100%;
  background: var(--ink);
  border: var(--border) solid var(--blue-deep);
  border-radius: var(--corners);
  overflow: hidden;
  box-shadow:
    0 4px 0 var(--blue-deep),
    0 24px 60px rgba(0, 0, 0, 0.5);
}

.comic-frame {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}
.comic-frame.is-swiping { cursor: grabbing; }

.comic-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #0a0908;
}
.comic-art-img {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: 108.5%;
  width: auto;
  max-width: none;
  min-width: 100%;
  object-fit: cover;
  object-position: center 100%;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  pointer-events: none;
}

/* Dissolve columns */
.comic-dissolve {
  position: absolute;
  inset: 0;
  display: flex;
  pointer-events: none;
  z-index: 12;
}
.dissolve-col {
  flex: 1;
  height: 100%;
  background-color: var(--ink);
  background-image:
    linear-gradient(180deg, transparent 0 6px, rgba(0,0,0,0.4) 6px 7px, transparent 7px 14px),
    linear-gradient(90deg, transparent 0 6px, rgba(255,255,255,0.03) 6px 7px, transparent 7px 14px);
  background-size: 14px 14px;
  transform: translateY(105%);
  opacity: 0;
  transition:
    transform 200ms var(--ease-out),
    opacity 200ms var(--ease-out);
}
.comic-dissolve.is-out .dissolve-col {
  transform: translateY(0);
  opacity: 1;
}
.dissolve-col:nth-child(1)  { transition-delay:   0ms; }
.dissolve-col:nth-child(2)  { transition-delay:  14ms; }
.dissolve-col:nth-child(3)  { transition-delay:  28ms; }
.dissolve-col:nth-child(4)  { transition-delay:  42ms; }
.dissolve-col:nth-child(5)  { transition-delay:  56ms; }
.dissolve-col:nth-child(6)  { transition-delay:  70ms; }
.dissolve-col:nth-child(7)  { transition-delay:  84ms; }
.dissolve-col:nth-child(8)  { transition-delay:  98ms; }
.dissolve-col:nth-child(9)  { transition-delay: 112ms; }
.dissolve-col:nth-child(10) { transition-delay: 126ms; }
.dissolve-col:nth-child(11) { transition-delay: 140ms; }
.dissolve-col:nth-child(12) { transition-delay: 154ms; }

/* ====== GLOBOS PIXEL JAGGED ====== */
.comic-bubbles {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}
.comic-bubble {
  position: absolute;
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.25;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--white);
  padding: 8px 12px 6px;
  display: grid;
  align-items: center;
  justify-items: center;
  text-align: center;
  transform-origin: var(--pop-origin, center);
  transform: scale(0.7);
  opacity: 0;
  transition:
    transform 180ms var(--ease-bounce),
    opacity 180ms var(--ease-out);
  image-rendering: pixelated;
  filter: drop-shadow(0 3px 0 rgba(0,0,0,0.18));
}
.comic-bubble.is-open {
  transform: scale(1);
  opacity: 1;
}
.comic-bubble-inner {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  width: 100%;
}
.comic-bubble-text {
  white-space: pre-wrap;
  text-align: center;
  text-transform: uppercase;
  word-break: break-word;
}
.comic-bubble-text::after {
  content: '';
  display: inline-block;
  width: 0.4em;
  height: 1em;
  background: var(--ink);
  margin-left: 2px;
  vertical-align: middle;
  animation: caret-blink 600ms steps(2) infinite;
}
.comic-bubble.is-done .comic-bubble-text::after { display: none; }

@keyframes caret-blink { 50% { opacity: 0; } }

/* Sprite pixel emoji */
.comic-sprite {
  display: inline-block;
  width: 11px;
  height: 11px;
  background: transparent;
  transform: scale(3);
  margin: 0 2px;
  flex-shrink: 0;
  image-rendering: pixelated;
}

/* ====== NAV INFERIOR ====== */
.comic-nav {
  position: relative;
  z-index: 5;
  height: var(--navbar-h);
  background:
    linear-gradient(0deg, var(--ink) 0%, #0f131c 100%);
  border-top: var(--border) solid var(--blue-deep);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 20px;
  box-shadow: 0 -4px 0 rgba(0,0,0,0.35);
}

.comic-arrow {
  height: 48px;
  min-width: 80px;
  padding: 0 18px;
  background: var(--blue);
  border: var(--border) solid var(--ink);
  border-radius: var(--corners);
  color: var(--white);
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition:
    transform var(--dur-quick) var(--ease-out),
    box-shadow var(--dur-quick) var(--ease-out),
    background var(--dur-quick) var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.comic-arrow:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--ink);
  background: var(--sky);
  color: var(--ink);
}
.comic-arrow:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--ink);
}
.comic-arrow:disabled {
  background: var(--ink);
  color: rgba(244, 234, 213, 0.3);
  cursor: not-allowed;
  box-shadow: 0 4px 0 rgba(0,0,0,0.5);
}

.comic-ruleta {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  position: relative;
}
.comic-dot {
  width: 18px;
  height: 18px;
  background: var(--cream);
  border: var(--border) solid var(--ink);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  transition: transform var(--dur-quick) var(--ease-out), background var(--dur-quick) var(--ease-out);
  position: relative;
  box-shadow: 0 2px 0 var(--ink);
}
.comic-dot:hover { transform: scale(1.18); }
.comic-dot.is-visited { background: var(--paper); }
.comic-dot.is-current {
  background: var(--blue);
  width: 28px;
  border-radius: 8px;
  box-shadow: 0 0 0 2px var(--sky), 0 2px 0 var(--ink);
  animation: dot-pulse 1.6s var(--ease-out) infinite;
}
@keyframes dot-pulse {
  50% { box-shadow: 0 0 0 6px rgba(143, 198, 232, 0.3), 0 2px 0 var(--ink); }
}

.comic-dot-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  padding: 4px 10px;
  background: var(--paper);
  color: var(--ink);
  border: var(--border) solid var(--ink);
  font-family: ui-monospace, "DejaVu Sans Mono", monospace;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--dur-quick) var(--ease-out), transform var(--dur-quick) var(--ease-out);
  box-shadow: 0 2px 0 var(--ink);
  z-index: 10;
}
.comic-dot:hover .comic-dot-tooltip,
.comic-dot:focus-visible .comic-dot-tooltip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== ELENCO PANEL ====== */
.comic-cast-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 19, 28, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out);
}
.comic-cast-overlay.is-open {
  opacity: 1;
  pointer-events: all;
}

.comic-cast {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 92vw);
  background:
    linear-gradient(180deg, var(--paper) 0%, var(--cream) 100%);
  border-left: var(--border) solid var(--ink);
  box-shadow: -8px 0 32px rgba(0,0,0,0.5);
  z-index: 101;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-out);
}
.comic-cast.is-open { transform: translateX(0); }

.comic-cast-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: var(--border) solid var(--ink);
  padding-bottom: 16px;
}
.comic-cast-titulo {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-stretch: condensed;
  font-weight: 700;
  font-size: 26px;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}
.comic-cast-sub {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ink-mute);
  margin-top: 4px;
}
.comic-cast-close {
  width: 40px; height: 40px;
  background: var(--ink);
  color: var(--white);
  border: none;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  border-radius: var(--corners);
  box-shadow: 0 3px 0 rgba(0,0,0,0.4);
  transition: transform var(--dur-quick) var(--ease-out);
}
.comic-cast-close:hover { transform: translateY(-1px); }
.comic-cast-close:active { transform: translateY(2px); }

.comic-cast-grid {
  display: grid;
  gap: 12px;
}
.comic-cast-card {
  background: var(--white);
  border: var(--border) solid var(--ink);
  border-radius: var(--corners);
  padding: 14px;
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 14px;
  align-items: center;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transition: transform var(--dur-quick) var(--ease-out), box-shadow var(--dur-quick) var(--ease-out);
}
.comic-cast-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 0 var(--ink);
}
.comic-cast-avatar {
  width: 56px; height: 56px;
  border: var(--border) solid var(--ink);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 22px;
  color: var(--white);
  text-shadow: 0 1px 0 rgba(0,0,0,0.3);
}
.comic-cast-info { min-width: 0; }
.comic-cast-name {
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-stretch: condensed;
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}
.comic-cast-rol {
  font-family: ui-monospace, monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  margin-top: 2px;
  font-weight: 600;
}
.comic-cast-card.is-active {
  border-color: var(--blue);
  box-shadow: 0 4px 0 var(--blue-deep), 0 0 0 4px var(--sky);
}

/* ====== FOCUS ====== */
.comic *:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 2px;
}

/* ====== SCENE FLASH ====== */
.comic-flash {
  position: absolute;
  inset: 0;
  background: var(--cream);
  opacity: 0;
  pointer-events: none;
  z-index: 11;
}
.comic-flash.is-flash {
  animation: scene-flash 80ms var(--ease-out);
}
@keyframes scene-flash {
  50% { opacity: 0.9; }
}

/* ====== HELP HINT ====== */
.comic-hint {
  position: absolute;
  bottom: 12px;
  right: 12px;
  z-index: 6;
  font-family: ui-monospace, monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: rgba(244, 234, 213, 0.45);
  background: rgba(15, 19, 28, 0.6);
  padding: 4px 8px;
  border-radius: 4px;
  pointer-events: none;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 1023px) {
  :root { --topbar-h: 48px; --navbar-h: 68px; }
  .comic-chapter-titulo { font-size: 16px; }
  .comic-stage { padding: 16px; }
  .comic-arrow { min-width: 64px; height: 44px; font-size: 16px; }
}

@media (max-width: 599px) {
  :root { --topbar-h: 44px; --navbar-h: 60px; }
  .comic-badge-text { display: none; }
  .comic-chapter-zona { display: none; }
  .comic-chapter-titulo { font-size: 14px; }
  .comic-ruleta { display: none; }
  .comic-nav { justify-content: space-between; }
  .comic-progress-counter { display: none; }
  .comic-stage { padding: 8px; }
  .comic-arrow { min-width: 60px; height: 40px; font-size: 14px; padding: 0 12px; }
  .comic-hint { display: none; }
  .comic-cast { width: 100vw; }
}

@media (max-width: 379px) {
  .comic-cast { padding: 16px; bottom: auto; height: 70vh; top: auto; border-radius: 16px 16px 0 0; transform: translateY(100%); }
  .comic-cast.is-open { transform: translateY(0); }
}

/* ====== REDUCED MOTION ====== */
@media (prefers-reduced-motion: reduce) {
  .comic *,
  .comic *::before,
  .comic *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .comic-bubble { transform: scale(1); opacity: 1; }
  .comic-bubble-text::after { display: none; }
  .comic-dissolve { display: none; }
  .dissolve-col { transform: none; opacity: 0; }
}