:root {
  color-scheme: light;
  --paper: #faf3e6;
  --ink: #171329;
  --yellow: #ffe900;
  --purple: #5c05a9;
  --purple-light: #9635ef;
  --bubble: #fff9cb;
  font-family: "Archivo Black", "Inter", system-ui, "Segoe UI", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--paper); }
body[data-topic="agrotech"] {
  --paper: #f5f2df;
  --bubble: #f1f6cf;
  --portraits: url("assets/comic/agro-portavoces.png");
}
body[data-topic="ia-empresa"] {
  --paper: #f6eff9;
  --bubble: #f4eaff;
  --portraits: url("assets/comic/empresa-portavoces.png");
}
body[data-topic="adopcion-ia"] {
  --paper: #fcf1e5;
  --bubble: #fff0d6;
  --portraits: url("assets/comic/adopcion-portavoces.png");
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 3px solid var(--purple); outline-offset: 4px; }
.comic {
  width: min(35rem, calc(100% - 1.35rem));
  margin-inline: auto;
  padding-block: .85rem .55rem;
}
.comic-bar { display: flex; justify-content: space-between; align-items: center; gap: .55rem; }
.comic-brand {
  color: var(--ink);
  font-weight: 900;
  font-size: clamp(.95rem, 4.2vw, 1.4rem);
  line-height: 1.2;
  letter-spacing: -.04em;
  text-decoration-thickness: .2em;
  text-underline-offset: .25em;
  text-decoration-color: var(--yellow);
}
.comic-topic {
  max-inline-size: 53%;
  min-height: 2.35rem;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: .68rem;
  padding: .24rem .57rem;
  font-weight: 800;
  font-size: clamp(.73rem, 3.3vw, .95rem);
}
h1 {
  position: relative;
  width: max-content;
  max-width: calc(100% - 2rem);
  margin: .78rem auto 0;
  text-align: center;
  font-size: clamp(1.65rem, 8.05vw, 3.32rem);
  line-height: 1.03;
  font-weight: 950;
  letter-spacing: -.07em;
}
h1::before, h1::after {
  content: "";
  position: absolute;
  width: .56em;
  height: .75em;
  top: 49%;
  translate: 0 -50%;
  background:
    linear-gradient(28deg, transparent 35%, var(--purple-light) 39% 61%, transparent 65%) right top / 80% 31% no-repeat,
    linear-gradient(var(--purple-light), var(--purple-light)) left center / 94% 13% no-repeat,
    linear-gradient(-28deg, transparent 35%, var(--purple-light) 39% 61%, transparent 65%) right bottom / 80% 31% no-repeat;
}
h1::before { right: calc(100% + .13em); }
h1::after { left: calc(100% + .13em); scale: -1 1; }
h1 span {
  display: inline-block;
  background: var(--yellow);
  border-radius: 6% 8% 4% 9% / 18% 27% 11% 21%;
  padding: .08em .23em .17em;
  rotate: -1.6deg;
}
.comic-reader {
  display: block;
  width: min(66%, 21rem);
  height: clamp(6.1rem, 32vw, 10rem);
  object-fit: contain;
  object-position: center bottom;
  margin: -.07rem auto -.22rem;
}
.comic-formats {
  position: relative;
  background: var(--paper);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 2px solid var(--ink);
  border-radius: .9rem;
  overflow: hidden;
}
.comic-formats button {
  min-height: 2.75rem;
  padding: .35rem .14rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: clamp(.8rem, 3.7vw, 1rem);
  font-weight: 850;
}
.comic-formats button + button { border-inline-start: 2px solid var(--ink); }
.comic-formats button[aria-pressed="true"] { background: var(--yellow); }
.comic-formats button:focus-visible { outline-offset: -5px; }
.comic-extra {
  margin-block-start: .5rem;
  border: 1.5px solid var(--ink);
  border-radius: .65rem;
  background: #fffaf1;
  font-size: .88rem;
}
.comic-extra { display: flex; align-items: center; gap: .5rem; min-height: 2.75rem; padding: .35rem .7rem; }
.comic-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  column-gap: .35rem;
  margin: .28rem .15rem 0;
  padding: 0;
  border: 0;
  min-width: 0;
}
.comic-columns label {
  display: flex;
  align-items: center;
  gap: .32rem;
  min-height: 2rem;
  padding: .05rem .1rem;
  font-size: clamp(.72rem, 2.9vw, .85rem);
  line-height: 1.15;
}
.comic-columns label:has(:disabled) { color: #5a4b65; }
input[type="checkbox"] { accent-color: var(--purple); width: 1rem; height: 1rem; margin: 0; flex: 0 0 auto; }

.comic-scene { --speaker: 37.5%; margin-block-start: .8rem; }
.comic-scene[data-speaker="0"] { --speaker: 12.5%; }
.comic-scene[data-speaker="2"] { --speaker: 62.5%; }
.comic-scene[data-speaker="3"] { --speaker: 87.5%; }
.comic-bubble {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 6.8rem;
  padding: .85rem clamp(.7rem, 4.8vw, 1.65rem);
  background: var(--bubble);
  border: 3px solid var(--ink);
  border-radius: 9% 12% 9% 12% / 23% 25% 21% 24%;
}
.comic-bubble p {
  margin: 0;
  text-align: center;
  font-size: clamp(1.22rem, 5.1vw, 2rem);
  line-height: 1.17;
  letter-spacing: -.04em;
  font-weight: 850;
  overflow-wrap: anywhere;
}
.comic-scene[data-speaker="2"] .comic-bubble p,
.comic-scene[data-speaker="3"] .comic-bubble p {
  font-size: clamp(1.05rem, 4.4vw, 1.65rem);
  line-height: 1.25;
}
.comic-bubble::before, .comic-bubble::after {
  content: "";
  position: absolute;
  z-index: 1;
  left: var(--speaker);
  top: calc(100% - 1px);
  width: 1.9rem;
  height: 1.45rem;
  translate: -.35rem 0;
  clip-path: polygon(6% 0, 99% 0, 14% 100%);
  pointer-events: none;
}
.comic-bubble::before { background: var(--ink); }
.comic-bubble::after {
  background: var(--bubble);
  top: calc(100% - 4px);
  translate: -.2rem 0;
  width: 1.55rem;
  height: 1.36rem;
}
.comic-cast {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .27rem;
  padding-block-start: 1.05rem;
}
.comic-portrait {
  aspect-ratio: 1;
  background: var(--portraits, url("assets/comic/portavoces.png")) 0 0 / 200% 200% no-repeat;
  filter: grayscale(1);
  opacity: .72;
}
.comic-portrait[data-portrait="1"] { background-position: 100% 0; }
.comic-portrait[data-portrait="2"] { background-position: 0 100%; }
.comic-portrait[data-portrait="3"] { background-position: 100% 100%; }
.comic-portrait[aria-current="true"] {
  opacity: 1;
  filter: drop-shadow(2px 0 var(--purple-light)) drop-shadow(-2px 0 var(--purple-light))
    drop-shadow(0 -2px var(--purple-light));
}

.comic-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: .65rem 0 max(.3rem, env(safe-area-inset-bottom, 0px));
  background: var(--paper);
}
.comic-buttons { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(0, 1fr); gap: .55rem; }
.comic-buttons button {
  min-height: 2.9rem;
  padding: .35rem .35rem;
  border: 2px solid var(--purple);
  border-radius: .8rem;
  font-size: clamp(.85rem, 4vw, 1.2rem);
  font-weight: 900;
}
.comic-generate { background: var(--purple); color: #fff; }
.comic-copy { background: transparent; color: #290847; }
.comic-feedback {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: .2rem .6rem;
  min-height: 1.11rem;
  padding-block-start: .26rem;
  color: #5a4b65;
  font-size: .75rem;
}
.comic-feedback p { margin: 0; }
.comic-feedback p:empty { display: none; }

@media (min-width: 45rem) {
  .comic { padding-block-start: 1.15rem; }
  .comic-actions { position: static; }
}
