/* ==========================================================================
   Piensacuentos · MagicSTEAM — Estilos generales (cálido, claro y responsive)
   ========================================================================== */

:root {
  --bg-paper: #fbf7ee;
  --bg-card: #ffffff;
  --bg-warm: #f6efe0;
  --ink: #1e293b;
  --ink-soft: #475569;
  --border: #e5dcc8;
  --forest: #20744a;
  --forest-dark: #165636;
  --forest-soft: #e6f5ec;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --blue: #2563eb;
  --blue-soft: #dbeafe;
  --danger: #dc2626;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 8px 24px rgba(51, 39, 18, 0.07);
  --font-ui: "Trebuchet MS", "Segoe UI Rounded", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-escolar: "Segoe Script", "Bradley Hand", "Snell Roundhand", "Comic Sans MS", cursive;
  --drop-marker-color: #2563eb;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, rgba(254, 240, 138, 0.35), transparent 34%),
    radial-gradient(circle at 88% 12%, rgba(167, 243, 208, 0.32), transparent 34%),
    var(--bg-paper);
  min-height: 100dvh;
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

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

.print-only {
  display: none;
}

/* ---------------- Barra superior ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem clamp(0.9rem, 2.5vw, 1.8rem);
  background: rgba(255, 253, 247, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 2px solid var(--border);
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand-mark {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.brand-logo {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 12px;
  background: linear-gradient(135deg, #22c55e, #15803d);
  font-size: 1.35rem;
  box-shadow: 0 4px 10px rgba(21, 128, 61, 0.25);
}

.brand-name {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--forest-dark);
  line-height: 1.1;
}

.brand-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.topbar-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

/* Selector de tipografía */
.font-switcher {
  display: inline-flex;
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 2px;
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  cursor: pointer;
  min-height: 34px;
}

.seg-btn-cursive {
  font-family: var(--font-escolar);
  font-size: 0.95rem;
}

.seg-btn.is-active {
  background: var(--forest);
  color: #ffffff;
}

/* Botones reutilizables */
button {
  font-family: inherit;
}

.btn-primary,
.btn-soft,
.btn-amber,
.btn-flag,
.btn-stop,
.btn-speak,
.btn-icon-pill,
.btn-primary-soft {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  padding: 0.52rem 1rem;
  min-height: 40px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.12s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--forest);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(32, 116, 74, 0.25);
}
.btn-primary:hover {
  background: var(--forest-dark);
  transform: translateY(-1px);
}

.btn-primary-soft {
  background: var(--forest-soft);
  color: var(--forest-dark);
  border-color: #a7e0be;
}
.btn-primary-soft:hover {
  background: #d2f0de;
}

.btn-soft,
.btn-icon-pill {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--border);
}
.btn-soft:hover,
.btn-icon-pill:hover {
  background: var(--bg-warm);
}
.btn-soft:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-amber {
  background: #fef3c7;
  color: #92400e;
  border-color: #fcd34d;
}
.btn-amber:hover {
  background: #fde68a;
}

.btn-flag {
  background: linear-gradient(180deg, #22c55e, #16a34a);
  color: #ffffff;
  border-color: #15803d;
  font-size: 1rem;
  padding: 0.58rem 1.25rem;
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}
.btn-flag:hover:not(:disabled) {
  background: linear-gradient(180deg, #16a34a, #15803d);
  transform: translateY(-1px);
}
.btn-flag:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-stop {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}
.btn-stop:hover:not(:disabled) {
  background: #fecaca;
}
.btn-stop:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-speak {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
  flex-shrink: 0;
}
.btn-speak:hover {
  background: #dbeafe;
}

.btn-xs {
  font-size: 0.82rem;
  padding: 0.32rem 0.72rem;
  min-height: 34px;
}

/* ---------------- Aviso superior amable ---------------- */
.notice-banner {
  max-width: 1280px;
  margin: 0.75rem auto 0;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  font-weight: 600;
  border: 2px solid #93c5fd;
  background: #eff6ff;
  color: #1e3a8a;
}
.notice-banner[hidden] {
  display: none;
}
.notice-banner[data-kind="warn"] {
  border-color: #fcd34d;
  background: #fffbeb;
  color: #92400e;
}
.notice-banner[data-kind="ok"] {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}
.notice-close {
  border: 0;
  background: transparent;
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  color: inherit;
  padding: 0.2rem 0.5rem;
}

/* ---------------- Vista Portada ---------------- */
.home-view {
  max-width: 1180px;
  margin: 0 auto;
  padding: 1.5rem clamp(0.9rem, 2.5vw, 1.8rem) 3rem;
}

.hero-card {
  background: linear-gradient(135deg, #fffdf7 0%, #f1fbf4 100%);
  border: 2px solid #d5eadc;
  border-radius: 26px;
  padding: clamp(1.3rem, 3vw, 2.2rem);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.9fr);
  gap: 1.5rem;
  align-items: center;
  box-shadow: var(--shadow-card);
}

.hero-kicker {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--forest);
  background: var(--forest-soft);
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
}

.hero-copy h1 {
  margin: 0.65rem 0 0.6rem;
  font-size: clamp(1.65rem, 3vw, 2.35rem);
  line-height: 1.15;
  color: #133c27;
}

.hero-copy p {
  margin: 0 0 1.2rem;
  color: var(--ink-soft);
  font-size: 1.04rem;
}

.hero-cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.hero-steps {
  display: grid;
  gap: 0.7rem;
}

.mini-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.95rem;
  font-size: 0.94rem;
}

.mini-step span {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: #fef08a;
  color: #854d0e;
}

.catalog-section {
  margin-top: 2rem;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.section-head h2 {
  margin: 0;
  font-size: 1.35rem;
}

.muted-note {
  font-size: 0.88rem;
  color: var(--ink-soft);
}

.catalog-grid {
  display: grid;
  gap: 1.25rem;
}

.story-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 24px;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
  box-shadow: var(--shadow-card);
}

.story-card-art {
  background: #dff5ff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.story-card-body {
  padding: 1.35rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.story-card-body h2 {
  margin: 0;
  font-size: 1.45rem;
  color: #133c27;
}

.story-card-body p {
  margin: 0;
  color: var(--ink-soft);
}

.story-card-badges,
.story-concepts,
.story-progress-row,
.story-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
}

.concept-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: #334155;
}

.story-progress-row {
  padding: 0.55rem 0.8rem;
  background: var(--bg-warm);
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  gap: 1rem;
}

/* Banda de impacto comunitario anónimo (Microsoft Azure Functions + Table Storage) */
.impact-strip {
  margin-top: 1.8rem;
  padding: 1.05rem 1.25rem;
  background: linear-gradient(135deg, #f0f9ff 0%, #f0fdf4 100%);
  border: 2px solid #bae6fd;
  border-radius: 20px;
}
.impact-strip[hidden] {
  display: none;
}
.impact-strip-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}
.impact-kicker {
  font-weight: 800;
  color: #0369a1;
  font-size: 0.92rem;
}
.impact-privacy {
  font-size: 0.8rem;
  font-weight: 700;
  color: #0f766e;
  background: #ccfbf1;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
}
.impact-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.65rem;
}
.impact-stat {
  background: #ffffff;
  border: 1.5px solid #e0f2fe;
  border-radius: 14px;
  padding: 0.65rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.impact-stat strong {
  font-size: 1.15rem;
  color: #0f172a;
}
.impact-stat span {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.22rem 0.68rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
}
.chip-green {
  background: var(--forest-soft);
  color: var(--forest-dark);
}
.chip-amber {
  background: var(--amber-soft);
  color: #92400e;
}
.chip-blue {
  background: var(--blue-soft);
  color: #1e40af;
}
.chip-gold {
  background: #fef08a;
  color: #854d0e;
}
.chip-gold.is-variant {
  background: #eff6ff;
  color: #1e40af;
  border: 1.5px dashed #60a5fa;
}

/* ---------------- Vista Lector Interactivo ---------------- */
.reader-view {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0.9rem clamp(0.75rem, 2vw, 1.5rem) 2.5rem;
}

.scene-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.65rem;
}

.scene-meta-left {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.story-crumb {
  font-weight: 800;
  color: var(--forest-dark);
  font-size: 0.95rem;
}

.scene-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* Selector de 3 niveles */
.level-switcher {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 4px;
}

.level-btn {
  border: 0;
  background: transparent;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.38rem 0.78rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}
.level-btn strong {
  font-size: 0.86rem;
}
.level-btn span {
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.level-btn.is-active {
  background: var(--forest);
  color: #ffffff;
  box-shadow: 0 3px 8px rgba(32, 116, 74, 0.24);
}
.level-btn.is-active span {
  color: #dcfce7;
}

/* Navegación de escenas */
.scene-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.scene-dots {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
}

.scene-dot {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: #ffffff;
  color: var(--ink);
  font-weight: 800;
  font-size: 0.84rem;
  cursor: pointer;
}
.scene-dot.is-done {
  border-color: #22c55e;
  background: #dcfce7;
  color: #166534;
}
.scene-dot.is-current {
  border-color: var(--forest-dark);
  background: var(--forest);
  color: #ffffff;
  transform: scale(1.08);
}

/* Doble página de libro abierto */
.book-spread {
  display: grid;
  grid-template-columns: minmax(0, 1.06fr) minmax(0, 1fr);
  gap: 1.15rem;
  align-items: start;
}

.book-page {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: clamp(0.95rem, 1.8vw, 1.35rem);
  box-shadow: var(--shadow-card);
}

.story-header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.scene-heading {
  margin: 0;
  font-size: clamp(1.18rem, 2vw, 1.48rem);
  color: #133c27;
}

.stage-wrap {
  position: relative;
}

.stage-frame {
  border-radius: 16px;
  overflow: hidden;
  border: 2px solid #d5e6da;
  background: #dff5ff;
  aspect-ratio: 16 / 10;
}

/* Subtítulo visual de efectos sonoros y música (accesibilidad auditiva) */
.stage-sound-caption {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  padding: 0.42rem 0.9rem;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.92);
  color: #ffffff;
  border: 2px solid #fde047;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.34);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.3;
  text-align: center;
  pointer-events: none;
  z-index: 6;
}
.stage-sound-caption[hidden] {
  display: none;
}

.stage-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.stage-sprite {
  transition: transform 0.24s ease-out;
}

/* Interruptor "¿Y si...?" (condicional) */
.conditional-box {
  margin-top: 0.8rem;
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-md);
  background: #fef9c3;
  border: 2px solid #facc15;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}
.switch-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--forest);
  cursor: pointer;
}
.switch-row strong {
  display: block;
  font-size: 0.96rem;
}
.switch-row small {
  color: #713f12;
  font-weight: 600;
}

/* Barra de control del modo Paso a paso */
.step-control-bar {
  margin-top: 0.8rem;
  padding: 0.78rem 0.95rem;
  border-radius: var(--radius-md);
  background: #ecfdf5;
  border: 2.5px solid #10b981;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.16);
}
.step-control-bar[hidden] {
  display: none;
}
.step-control-copy {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  font-weight: 700;
  color: #064e3b;
  font-size: 0.96rem;
  flex: 1 1 220px;
}
.step-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.18rem 0.58rem;
  border-radius: 999px;
  background: #065f46;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
}
.step-control-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}
.btn-step-next {
  border: 0;
  background: #15803d;
  color: #ffffff;
  border-radius: 999px;
  padding: 0.58rem 1.2rem;
  min-block-size: 46px;
  font-size: 0.98rem;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 3px 0 #14532d;
  transition: transform 0.1s ease, background-color 0.14s ease;
}
.btn-step-next:hover {
  background: #166534;
  transform: translateY(-1px);
}
.btn-step-next:active {
  transform: translateY(1px);
}

/* Botón Lectura fácil en barra superior */
.btn-easy-toggle {
  border: 2px solid #99f6e4;
  background: #f0fdfa;
  color: #115e59;
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  min-block-size: 40px;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn-easy-toggle:hover {
  background: #ccfbf1;
}
.btn-easy-toggle.is-active {
  background: #0f766e;
  border-color: #0f766e;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(15, 118, 110, 0.28);
}

/* Botón Subtítulos de sonido en barra superior */
.btn-captions-toggle {
  border: 2px solid #c7d2fe;
  background: #eef2ff;
  color: #312e81;
  border-radius: 999px;
  padding: 0.42rem 0.85rem;
  min-block-size: 40px;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn-captions-toggle:hover {
  background: #e0e7ff;
}
.btn-captions-toggle.is-active {
  background: #3730a3;
  border-color: #3730a3;
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(55, 48, 163, 0.28);
}

html[data-easy-read="true"] .stage-sound-caption {
  font-size: 1rem;
  padding: 0.52rem 1.05rem;
}

/* Texto del cuento y modos tipográficos */
.story-text-card {
  margin-top: 0.85rem;
  padding: 1rem 1.15rem;
  border-radius: var(--radius-md);
  background: #fffdf6;
  border: 1.5px solid #efe4cb;
}

.easy-read-tag {
  display: inline-flex;
  align-items: center;
  margin-bottom: 0.65rem;
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  background: #ccfbf1;
  color: #115e59;
  font-size: 0.78rem;
  font-weight: 800;
}
.easy-read-tag[hidden] {
  display: none;
}

.story-prose {
  margin: 0;
  font-size: 1.16rem;
  line-height: 1.68;
  color: #1e293b;
}
.story-prose p {
  margin: 0;
}
.story-prose .easy-line {
  margin: 0 0 0.72rem;
  padding: 0.12rem 0 0.12rem 0.65rem;
  border-left: 3.5px solid #5eead4;
}
.story-prose .easy-line:last-child {
  margin-bottom: 0;
}

html[data-font-mode="mayusculas"] .story-prose,
html[data-font-mode="mayusculas"] .scene-heading {
  text-transform: uppercase;
  letter-spacing: 0.045em;
  font-weight: 700;
}

html[data-font-mode="escolar"] .story-prose,
html[data-font-mode="escolar"] .scene-heading {
  font-family: var(--font-escolar);
  font-size: 1.28rem;
  line-height: 1.72;
}

/* Página derecha: Reto y zona de código */
.challenge-card {
  background: #fffbeb;
  border: 2px solid #fde68a;
  border-radius: var(--radius-md);
  padding: 0.8rem 0.95rem;
  margin-bottom: 0.85rem;
}

.challenge-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.challenge-badge {
  font-size: 0.82rem;
  font-weight: 800;
  color: #92400e;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.challenge-prose {
  margin: 0.45rem 0 0;
  font-size: 0.97rem;
  font-weight: 600;
}

.hint-details summary {
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 700;
  color: #b45309;
  list-style: none;
}
.hint-details p {
  margin: 0.35rem 0 0;
  font-size: 0.88rem;
  color: #78350f;
}

.run-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.speed-switcher {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.22rem;
  padding: 3px;
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  margin-left: auto;
}

.speed-btn {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.34rem 0.65rem;
  font-size: 0.8rem;
  font-weight: 800;
  cursor: pointer;
  min-height: 34px;
  transition: background 0.15s ease, color 0.15s ease;
}

.speed-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.7);
}

.speed-btn.is-active {
  background: #ffffff;
  color: var(--forest-dark);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.12);
}

.feedback-box {
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-md);
  margin-bottom: 0.75rem;
  font-weight: 700;
  font-size: 0.95rem;
}
.feedback-box[hidden] {
  display: none;
}
.feedback-box[data-kind="ok"] {
  background: #dcfce7;
  color: #166534;
  border: 2px solid #4ade80;
}
.feedback-box[data-kind="warn"] {
  background: #fef3c7;
  color: #92400e;
  border: 2px solid #fbbf24;
}
.feedback-box[data-kind="funny"] {
  background: #fdf2f8;
  color: #9d174d;
  border: 2px solid #f472b6;
}

/* Pestañas de personajes */
.actor-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
}

.actor-tab {
  border: 2px solid var(--border);
  background: var(--bg-warm);
  color: var(--ink);
  border-radius: 12px 12px 0 0;
  padding: 0.42rem 0.85rem;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: 38px;
}
.actor-tab.is-active {
  background: #ffffff;
  border-color: var(--forest);
  color: var(--forest-dark);
}

.workspace-box {
  background:
    radial-gradient(#d8d2c5 1.2px, transparent 1.2px) 0 0 / 18px 18px,
    #faf9f5;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 0.9rem;
  min-height: 220px;
  overflow-x: auto;
}

.palette-box {
  margin-top: 0.85rem;
  padding: 0.8rem 0.9rem;
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 16px;
}

.palette-title {
  margin: 0 0 0.55rem;
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--ink-soft);
}

.block-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.creator-tools {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* ---------------- Modales nativos <dialog> (Modern Web Guidance) ---------------- */
dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(3px);
}

.app-dialog {
  width: min(860px, calc(100vw - 1.5rem));
  max-height: calc(100dvh - 2rem);
  border: 2px solid var(--border);
  border-radius: 24px;
  padding: 1.25rem 1.4rem;
  background: #fffdf8;
  color: var(--ink);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.25);
}

.app-dialog-wide {
  width: min(1040px, calc(100vw - 1.5rem));
}

.app-dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.dialog-head h1 {
  margin: 0;
  font-size: 1.4rem;
  color: #133c27;
}

.dialog-sub {
  margin: 0.2rem 0 0;
  color: var(--ink-soft);
  font-size: 0.92rem;
}

.btn-close-dialog {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 2px solid var(--border);
  background: #ffffff;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
}
.btn-close-dialog:hover {
  background: #fee2e2;
  border-color: #fca5a5;
}

.dialog-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.dialog-tab {
  border: 2px solid var(--border);
  background: var(--bg-warm);
  border-radius: 999px;
  padding: 0.45rem 1rem;
  font-weight: 800;
  cursor: pointer;
}
.dialog-tab.is-active {
  background: var(--forest);
  border-color: var(--forest);
  color: #ffffff;
}

/* Tutorial */
.tut-banner {
  background: #fffbeb;
  border: 2px solid #fde68a;
  border-radius: 14px;
  padding: 0.7rem 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}
.tut-banner p {
  margin: 0;
  font-weight: 700;
}

.tut-grid {
  margin-top: 0.85rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.tut-stack {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 0.8rem;
  padding: 0.8rem 0.75rem 0.95rem;
  background: #faf9f5;
  border: 2px solid var(--border);
  border-radius: 14px;
}

.tut-actions {
  margin-top: 0.8rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.glossary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0.75rem;
}

.glossary-card {
  display: flex;
  gap: 0.75rem;
  padding: 0.85rem;
  background: #ffffff;
  border: 2px solid var(--border);
  border-radius: 16px;
}
.glossary-card h2 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}
.glossary-card p {
  margin: 0 0 0.4rem;
  font-size: 0.88rem;
  color: var(--ink-soft);
}
.glossary-sample {
  font-size: 0.8rem;
  font-weight: 700;
  background: #f8fafc;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
}
.glossary-dot {
  width: 18px;
  height: 18px;
  border-radius: 6px;
  flex-shrink: 0;
  margin-top: 3px;
}
.glossary-card.cat-event .glossary-dot { background: #ffbf00; }
.glossary-card.cat-control .glossary-dot { background: #ffab19; }
.glossary-card.cat-motion .glossary-dot { background: #4c97ff; }
.glossary-card.cat-looks .glossary-dot { background: #9966ff; }
.glossary-card.cat-sound .glossary-dot { background: #cf63cf; }
.glossary-card.cat-custom .glossary-dot { background: #ff6680; }

/* Modal Libro y QR */
.qr-config-bar {
  background: var(--bg-warm);
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 0.85rem 1rem;
}

.qr-label {
  display: block;
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
}

.qr-url-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.qr-url-input {
  flex: 1 1 260px;
  min-height: 40px;
  padding: 0.45rem 0.75rem;
  border-radius: 10px;
  border: 2px solid var(--border);
  font-size: 0.92rem;
}

.qr-hint {
  margin: 0.45rem 0 0;
  font-size: 0.84rem;
  color: var(--ink-soft);
}

.qr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 0.8rem;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.qr-scene-card {
  display: flex;
  gap: 0.8rem;
  padding: 0.75rem;
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  align-items: center;
}

.qr-card-code {
  width: 92px;
  height: 92px;
  flex-shrink: 0;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
}
.qr-card-code svg {
  width: 100%;
  height: 100%;
  display: block;
}

.qr-card-info {
  min-width: 0;
  flex: 1;
}
.qr-card-num {
  font-size: 0.76rem;
  font-weight: 800;
  color: var(--forest);
}
.qr-card-info h2 {
  margin: 0.15rem 0;
  font-size: 0.96rem;
}
.qr-card-url {
  margin: 0 0 0.45rem;
  font-size: 0.74rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qr-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

/* ---------------- Responsive: Tablet y Móvil ---------------- */
@media (max-width: 1020px) {
  .book-spread {
    grid-template-columns: 1fr;
  }
  .hero-card,
  .story-card,
  .tut-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    position: static;
    padding: 0.55rem 0.75rem;
  }
  .brand-sub {
    display: none;
  }
  .scene-nav-bar {
    flex-wrap: wrap;
  }
  .scene-dots {
    order: 3;
    width: 100%;
  }
  .story-prose {
    font-size: 1.08rem;
  }
  .speed-switcher {
    margin-left: 0;
    width: 100%;
    justify-content: space-between;
  }
  .speed-btn {
    flex: 1;
    padding: 0.34rem 0.4rem;
    font-size: 0.78rem;
  }
}

/* ==========================================================================
   Modo Lectura Fácil y Calma (accesibilidad cognitiva / DUA)
   ========================================================================== */
html[data-easy-read="true"] .brand-sub,
html[data-easy-read="true"] #scene-concept,
html[data-easy-read="true"] #scene-dots,
html[data-easy-read="true"] #btn-glossary {
  display: none !important;
}

html[data-easy-read="true"] .story-text-card {
  background: #ffffff;
  border-color: #99f6e4;
  border-width: 2px;
  padding: 1.2rem 1.35rem;
}

html[data-easy-read="true"] .story-prose {
  font-size: 1.28rem;
  line-height: 1.85;
  letter-spacing: 0.015em;
}

html[data-easy-read="true"] .workspace-box {
  background: #fcfbf7;
  padding: 1.05rem;
}

html[data-easy-read="true"] .challenge-prose {
  font-size: 1.08rem;
  line-height: 1.55;
}

html[data-easy-read="true"] .btn-flag,
html[data-easy-read="true"] .btn-stop,
html[data-easy-read="true"] .btn-soft,
html[data-easy-read="true"] .btn-speak,
html[data-easy-read="true"] .actor-tab,
html[data-easy-read="true"] .speed-btn {
  min-block-size: 48px;
  font-size: 0.98rem;
}

html[data-easy-read="true"] .scene-nav-bar {
  justify-content: space-between;
}

@media (pointer: coarse) {
  .speed-btn,
  .seg-btn,
  .actor-tab,
  .scene-dot {
    min-block-size: 44px;
    min-inline-size: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
