:root {
  --noche-1: #0d1430;
  --noche-2: #1a2756;
  --noche-3: #26386f;
  --tinta: #1b2340;
  --papel: #f3f6ff;
  --papel-2: #e4eafb;
  --texto: #eef1ff;
  --suave: #aab4dd;
  --luz: #ffd66b;
  --luz-2: #fff1b8;
  --chispa: #d8ff8a;
  --calma: #8fe3b0;
  --accion: #ffd66b;
  --tormenta: #9aa3c7;
  --radio: 18px;
  --v: 0;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--noche-1);
  color: var(--texto);
  font: 18px/1.45 "Atkinson Hyperlegible", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, [tabindex]:focus-visible { outline: 3px solid var(--luz); outline-offset: 3px; }
h1, h2, h3, .marca { font-family: "Baloo 2", system-ui, sans-serif; font-weight: 800; line-height: 1.1; }

#app {
  max-width: 980px; margin: 0 auto; min-height: 100%;
  display: grid; grid-template-rows: auto auto 1fr;
}

/* ---------- barra ---------- */
.barra {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.marca { background: none; border: 0; font-size: 26px; color: var(--luz); padding: 0; letter-spacing: .5px; }
.progreso { flex: 1; display: flex; gap: 5px; flex-wrap: wrap; align-items: center; justify-content: center; min-height: 20px; }
.progreso i { width: 11px; height: 11px; border-radius: 50%; background: #2f3d73; display: block; transition: background .4s, box-shadow .4s; }
.progreso i.on { background: var(--luz); box-shadow: 0 0 8px var(--luz); }
.acciones-barra { display: flex; gap: 6px; }
@media (max-width: 620px) {
  .barra { flex-wrap: wrap; row-gap: 8px; }
  .marca { flex: 1; text-align: left; }
  .progreso { order: 3; flex-basis: 100%; justify-content: flex-start; }
}
.icono {
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: #1f2b5c; display: grid; place-items: center;
}
.icono svg { width: 22px; height: 22px; stroke: var(--texto); stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icono svg path:first-child, .icono svg circle { fill: none; }
.icono[aria-pressed="false"] { opacity: .45; }
.icono.hablando { background: var(--luz); }
.icono.hablando svg { stroke: var(--tinta); }

/* ---------- escena ---------- */
.escena-marco { position: relative; padding: 0 16px; }
.escena {
  height: clamp(190px, 34vh, 320px); border-radius: var(--radio); overflow: hidden;
  background: linear-gradient(180deg, var(--noche-1), var(--noche-2) 60%, var(--noche-3));
}
.escena svg { width: 100%; height: 100%; display: block; }
.estrella { fill: #fff; animation: titilar 3s ease-in-out infinite; }
@keyframes titilar { 50% { opacity: .25; } }
.cerro-1 { fill: #16224a; }
.cerro-2 { fill: #101a3b; }
.casa { fill: #0b1230; }
.ventana { fill: #222c55; transition: fill .8s, filter .8s; }
.ventana.on { fill: var(--luz); filter: drop-shadow(0 0 6px var(--luz)); }

.poste { fill: #0b1230; }
.farol-marco { fill: none; stroke: #0b1230; stroke-width: 6; stroke-linejoin: round; }
.farol-vidrio { fill: rgba(170, 190, 255, .10); transition: fill .8s; }
.farol-halo { opacity: 0; transition: opacity 1s; }
.llama-g { transform-box: fill-box; transform-origin: 50% 100%; opacity: 0; transition: opacity .5s; }
.llama-g.viva { opacity: 1; animation: llama calc(1.6s - var(--v) * .22s) ease-in-out infinite alternate; }
.llama-ext { fill: var(--luz); }
.llama-int { fill: var(--luz-2); }
@keyframes llama {
  0%   { transform: skewX(calc(var(--v) * 2deg)) scaleY(calc(1 - var(--v) * .04)); }
  50%  { transform: skewX(calc(var(--v) * -3.5deg)) scaleY(calc(1 - var(--v) * .07)) scaleX(calc(1 + var(--v) * .03)); }
  100% { transform: skewX(calc(var(--v) * -5deg)) scaleY(calc(1 - var(--v) * .02)); }
}
.encendido .farol-halo { opacity: 1; }
.encendido .farol-vidrio { fill: rgba(255, 214, 107, .35); }
.encendido .llama-g.viva { animation: llama 2.4s ease-in-out infinite alternate; --v: .2; }

.viento path { fill: none; stroke: #c8d4ff; stroke-width: 2.5; stroke-linecap: round;
  opacity: calc(var(--v) * .16); stroke-dasharray: 60 400;
  animation: soplar calc(2.6s - var(--v) * .35s) linear infinite; }
.viento path:nth-child(2) { animation-delay: -.8s; }
.viento path:nth-child(3) { animation-delay: -1.5s; }
.viento path:nth-child(4) { animation-delay: -2.1s; }
@keyframes soplar { from { stroke-dashoffset: 460; } to { stroke-dashoffset: 0; } }

.chispa-g { animation: revolotear 4s ease-in-out infinite; }
.chispa-luz { fill: var(--chispa); filter: drop-shadow(0 0 8px var(--chispa)); }
.chispa-ala { fill: rgba(255, 255, 255, .55); transform-box: fill-box; transform-origin: 50% 100%; animation: aletear .18s ease-in-out infinite alternate; }
.chispa-ala.der { animation-delay: .09s; }
.chispa-cuerpo { fill: #33406f; }
@keyframes revolotear {
  0%, 100% { transform: translate(0, 0); }
  30% { transform: translate(10px, -8px); }
  65% { transform: translate(-6px, 6px); }
}
@keyframes aletear { to { transform: scaleY(.45); } }

.chispa-dice {
  position: absolute; left: 30px; right: 30px; bottom: 12px; margin: 0;
  background: rgba(13, 20, 48, .82); backdrop-filter: blur(4px);
  border: 1px solid #3a4a88; border-radius: 14px; padding: 8px 14px;
  font-size: 16px; color: var(--texto);
  opacity: 0; transform: translateY(6px); transition: opacity .3s, transform .3s;
}
.chispa-dice.ver { opacity: 1; transform: none; }
@media (max-width: 620px) {
  .chispa-dice { position: static; margin-top: 8px; min-height: 3.4em; font-size: 15px; }
}
.chispa-dice::before { content: "Chispa · "; color: var(--chispa); font-weight: 700; }

/* ---------- panel ---------- */
.panel { padding: 18px 16px 40px; }
.panel h1 { font-size: clamp(40px, 9vw, 64px); margin: 6px 0 6px; color: var(--luz); }
.panel h2 { font-size: 28px; margin: 4px 0 12px; }
.panel h3 { font-size: 21px; margin: 0 0 10px; color: var(--luz-2); }
.panel p { margin: 0 0 12px; }
.lead { color: var(--suave); font-size: 19px; max-width: 34em; }
.etiqueta { display: inline-block; font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: var(--suave); margin-bottom: 4px; }

.boton {
  border: 0; border-radius: 999px; padding: 14px 26px; font-weight: 700; font-size: 19px;
  background: var(--luz); color: var(--tinta); box-shadow: 0 4px 0 #b8922f;
  transition: transform .1s, box-shadow .1s, opacity .2s;
}
.boton:active { transform: translateY(3px); box-shadow: 0 1px 0 #b8922f; }
.boton:disabled { opacity: .35; cursor: default; }
.boton.sec { background: #263468; color: var(--texto); box-shadow: 0 4px 0 #141c40; }
.fila { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.fila.fin { justify-content: flex-end; }

.situacion {
  background: var(--papel); color: var(--tinta); border-radius: var(--radio);
  padding: 18px 20px; margin: 0 0 16px; position: relative;
  box-shadow: 0 6px 0 var(--papel-2);
}
.situacion .lugar { font-size: 14px; letter-spacing: .08em; text-transform: uppercase; color: #5a6696; display: block; margin-bottom: 4px; }
.situacion p { font-size: 22px; line-height: 1.35; margin: 0; font-weight: 700; }

/* bandas de edad */
.bandas { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 12px; }
.banda {
  background: #1f2b5c; border: 2px solid #33437e; border-radius: var(--radio); padding: 18px; text-align: left;
}
.banda b { display: block; font-family: "Baloo 2", sans-serif; font-size: 26px; color: var(--luz); }
.banda span { color: var(--suave); font-size: 16px; }
.banda:hover { border-color: var(--luz); }

/* emociones */
.emociones { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
@media (max-width: 560px) { .emociones { grid-template-columns: repeat(4, 1fr); gap: 6px; } }
.emo {
  border: 3px solid transparent; border-radius: 16px; padding: 8px 4px 6px;
  background: #1f2b5c; display: grid; justify-items: center; gap: 2px; font-size: 15px;
  transition: transform .15s, border-color .15s, background .15s;
}
.emo svg { width: min(64px, 15vw); height: min(64px, 15vw); }
.emo[aria-pressed="true"] { border-color: var(--c); background: #2a3a78; transform: translateY(-3px); }
.emo:disabled { opacity: .4; }
.pista { color: var(--suave); font-size: 16px; min-height: 1.4em; }

/* termómetro */
.termometro { display: flex; gap: 8px; align-items: flex-end; margin: 8px 0 4px; }
.nivel {
  flex: 1; border: 0; border-radius: 12px 12px 6px 6px; background: #26346a;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px;
  font-weight: 700; font-size: 18px; color: var(--suave);
  transition: background .2s, color .2s;
}
.nivel.on { background: var(--c, var(--luz)); color: var(--tinta); }
.nivel-texto { display: flex; justify-content: space-between; color: var(--suave); font-size: 15px; }
.lectura { font-size: 20px; font-weight: 700; color: var(--luz-2); min-height: 1.5em; margin-top: 8px; }

/* cuerpo */
.cuerpo-wrap { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 18px; align-items: center; }
@media (max-width: 480px) { .cuerpo-wrap { grid-template-columns: 1fr; justify-items: center; } }
.cuerpo svg { width: 100%; max-height: 300px; }
.zona { fill: #2b3a73; stroke: #4a5ba0; stroke-width: 2; cursor: pointer; transition: fill .2s; }
.zona.on { fill: var(--c, var(--luz)); }
.zona:focus-visible { outline: none; stroke: var(--luz); stroke-width: 4; }
.zonas-lista { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid #3a4a88; background: #1f2b5c; border-radius: 999px; padding: 6px 14px; font-size: 16px; }
.chip[aria-pressed="true"] { background: var(--c, var(--luz)); color: var(--tinta); border-color: transparent; }

/* viento + mano */
.medidor { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; font-size: 16px; color: var(--suave); }
.medidor .barra-v { flex: 1; height: 12px; border-radius: 99px; background: #26346a; overflow: hidden; }
.medidor .barra-v i { display: block; height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, #8fe3b0, #ffd66b 50%, #f28b9b); transition: width .6s; }
.medidor b { color: var(--texto); min-width: 6.5em; text-align: right; }

.mano { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 620px) { .mano { grid-template-columns: repeat(2, 1fr); } }
.carta {
  border: 0; border-radius: 16px; text-align: left; padding: 12px 12px 14px; min-height: 128px;
  background: var(--papel); color: var(--tinta); position: relative;
  border-top: 8px solid var(--t); display: flex; flex-direction: column; gap: 4px;
  transition: transform .2s, opacity .3s;
}
.carta:hover { transform: translateY(-3px); }
.carta .tipo { font-size: 12px; letter-spacing: .1em; text-transform: uppercase; color: #5a6696; font-weight: 700; }
.carta b { font-size: 18px; line-height: 1.2; }
.carta small { font-size: 14px; color: #3d4770; line-height: 1.3; }
.carta.calma { --t: var(--calma); }
.carta.accion { --t: var(--accion); }
.carta.tormenta { --t: var(--tormenta); }
.carta.usada { opacity: .38; transform: scale(.96); pointer-events: none; }
.carta.usada::after {
  content: "Usada"; position: absolute; top: 10px; right: 10px; font-size: 12px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; background: var(--tinta); color: var(--papel);
  border-radius: 99px; padding: 2px 8px;
}
.carta.no { animation: no .4s; }
@keyframes no { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.leyenda { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; color: var(--suave); margin-top: 12px; }
.leyenda span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; background: var(--t); }

.siguiente-idea { background: #1f2b5c; border-left: 5px solid var(--luz); border-radius: 12px; padding: 12px 16px; margin: 12px 0; }
.nueva-herr { display: inline-flex; gap: 8px; align-items: center; background: #26346a; border-radius: 999px; padding: 6px 14px; font-size: 16px; margin-top: 4px; }

/* bitácora */
.bitacora { width: 100%; border-collapse: collapse; font-size: 16px; margin-top: 8px; }
.bitacora th, .bitacora td { text-align: left; padding: 10px 8px; border-bottom: 1px solid #2f3d73; vertical-align: top; }
.bitacora th { color: var(--suave); font-weight: 700; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; }
.punto { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; background: var(--c); }
.resumen { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; margin: 12px 0; }
.resumen div { background: #1f2b5c; border-radius: 14px; padding: 12px 14px; }
.resumen b { display: block; font-size: 22px; color: var(--luz-2); }
.resumen span { font-size: 14px; color: var(--suave); }
@media (max-width: 560px) {
  .bitacora thead { display: none; }
  .bitacora tr { display: block; border-bottom: 1px solid #2f3d73; padding: 8px 0; }
  .bitacora td { display: block; border: 0; padding: 2px 0; }
}

/* diálogo */
dialog {
  border: 0; border-radius: 22px; padding: 22px; width: min(640px, calc(100vw - 32px));
  background: var(--noche-2); color: var(--texto); max-height: 86vh;
}
dialog::backdrop { background: rgba(5, 8, 22, .7); }
dialog h2 { font-family: "Baloo 2", sans-serif; margin: 0 0 10px; color: var(--luz); }
dialog textarea {
  width: 100%; min-height: 110px; border-radius: 12px; border: 2px solid #3a4a88; background: #121a3e;
  color: var(--texto); font: inherit; font-size: 16px; padding: 10px;
}
dialog ul { padding-left: 20px; }
.caja-lista { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 8px; list-style: none; padding: 0; }
.caja-lista li { background: #1f2b5c; border-radius: 12px; padding: 10px 12px; border-left: 6px solid var(--t); }
.caja-lista li.calma { --t: var(--calma); }
.caja-lista li.accion { --t: var(--accion); }
.caja-lista li.vacia { opacity: .4; border-left-color: #3a4a88; }
.caja-lista small { display: block; color: var(--suave); }
.nota { font-size: 14px; color: var(--suave); }

/* ---------- garúa y luz que viaja ---------- */
.garua line { stroke: #cfe0ff; stroke-width: 1.6; stroke-linecap: round;
  opacity: calc(var(--v) * .15); animation: caer calc(1.4s - var(--v) * .14s) linear infinite; }
@keyframes caer { from { transform: translate(6px, -60px); } to { transform: translate(-14px, 80px); } }
.viaje { fill: var(--luz); filter: drop-shadow(0 0 8px var(--luz)); transform-box: fill-box; transform-origin: center;
  transition: transform .9s cubic-bezier(.5, 0, .3, 1); }

/* ---------- ejercicios de calma ---------- */
.ejercicio { text-align: center; }
.ejercicio .lead { margin: 0 auto 8px; }
.ejercicio .fila.fin { justify-content: center; }
.ej-zona { min-height: 270px; display: grid; place-items: center; margin: 8px 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.ej-estado { font-size: 20px; font-weight: 700; color: var(--luz-2); min-height: 1.5em; }
.ej-burbuja {
  --s: .45; width: 240px; height: 240px; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 40% 35%, #c7f6d8, var(--calma) 55%, #4fb98a);
  transform: scale(var(--s)); display: grid; place-items: center; color: var(--tinta);
  font: 800 30px "Baloo 2", sans-serif; box-shadow: 0 0 0 10px rgba(143, 227, 176, .15);
}
.ej-burbuja span { transform: scale(calc(1 / var(--s))); }
.ej-grande {
  width: 190px; height: 190px; border-radius: 50%; border: 0; background: var(--luz); color: var(--tinta);
  font: 800 76px "Baloo 2", sans-serif; box-shadow: 0 8px 0 #b8922f; display: grid; place-items: center;
}
.ej-grande:active { transform: translateY(5px); box-shadow: 0 3px 0 #b8922f; }
.ej-grande.no { animation: no .4s; }
.ej-grande:disabled { opacity: 1; }
.ej-salto { background: #26346a; box-shadow: 0 8px 0 #141c40; }
.ej-salto svg { width: 120px; height: 120px; overflow: visible; }
.ej-salto.quieto { background: #1d2a5a; }
#ejChispa.salta { animation: salta .35s ease-out; }
@keyframes salta { 40% { transform: translateY(-34px) scale(1.05); } }
.ej-chispa-luz { fill: var(--chispa); filter: drop-shadow(0 0 8px var(--chispa)); }
.ej-chispa-cuerpo { fill: #7d8cc9; }
.ej-chispa-ala { fill: rgba(255, 255, 255, .6); }
.ej-palabra { position: relative; font: 800 34px "Baloo 2", sans-serif; color: var(--texto); }
.ej-sostener.activo .ej-palabra { transform: scale(.9); display: inline-block; }
.ej-sostener { position: relative; width: 220px; height: 220px; border: 0; border-radius: 50%; background: #1f2b5c; display: grid; place-items: center; }
.ej-sostener > svg:first-child { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.ej-aro-fondo { fill: none; stroke: #2f3d73; stroke-width: 10; }
.ej-aro { fill: none; stroke: var(--calma); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 100; stroke-dashoffset: 100; }
.ej-fig { width: 110px; height: 110px; transition: transform .25s; }
.ej-sostener.activo .ej-fig { transform: scale(.88); }
.ej-sostener.activo .ej-cojin { transform: scale(1.08, .82); }
.ej-sostener.lleno { background: #2a3f74; }
.ej-puño, .ej-cojin-forma { fill: var(--papel); }
.ej-cojin-forma { fill: #ffc2e2; }
.ej-linea { fill: none; stroke: var(--tinta); stroke-width: 3; stroke-linecap: round; }
.ej-cosas { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; width: min(560px, 100%); }
.ej-cosa { border: 3px solid transparent; border-radius: 16px; background: #1f2b5c; padding: 10px 4px 6px; display: grid; justify-items: center; gap: 2px; font-size: 15px; }
.ej-cosa svg { width: 54px; height: 54px; }
.ej-cosa path { fill: none; stroke: var(--texto); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.ej-cosa.vista { border-color: var(--luz); background: #2a3a78; }
.ej-cosa.vista path { stroke: var(--luz); }
.ej-campo { position: relative; width: min(560px, 100%); height: 250px; border-radius: 18px; background: #182250; overflow: hidden; }
.ej-rincon { position: absolute; right: 18px; top: 50%; transform: translateY(-50%); width: 140px; height: 140px; border-radius: 50%;
  border: 3px dashed var(--calma); display: grid; place-items: center; text-align: center; padding: 18px; font-size: 15px; color: var(--calma); cursor: pointer; }
.ej-arrastre { position: absolute; left: 24px; top: 93px; width: 64px; height: 64px; cursor: grab; touch-action: none; transition: left .5s, top .5s; }
.ej-arrastre:active { cursor: grabbing; transition: none; }
.ej-arrastre svg { width: 100%; height: 100%; }
.ej-arrastre.descansa { animation: respira-ch 2s ease-in-out infinite; }
@keyframes respira-ch { 50% { transform: scale(1.12); } }
@media (max-width: 480px) {
  .ej-cosas { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .ej-cosa { font-size: 13px; } .ej-cosa svg { width: 40px; height: 40px; }
  .ej-burbuja { width: 210px; height: 210px; }
}

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

/* ---------- impresión de la bitácora ---------- */
@media print {
  body { background: #fff; color: #000; font-size: 12pt; }
  .barra, .escena-marco, .fila, .no-imprimir, dialog { display: none !important; }
  .panel { padding: 0; }
  .panel h1, .panel h2, .panel h3 { color: #000; }
  .resumen div { background: #f2f2f2; }
  .resumen b { color: #000; }
  .resumen span, .bitacora th, .lead { color: #333; }
  .bitacora th, .bitacora td { border-bottom: 1px solid #bbb; }
}
