:root {
  --verde: #1f8a4c; --verde2: #2fa862; --rojo: #d7263d; --rojo2: #a81b2e; --oro: #f6c445;
  --texto: #fff; --suave: #f3dcc8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #2a0f12; color: var(--texto); overflow: hidden;
  font-family: 'Nunito', system-ui, sans-serif; -webkit-font-smoothing: antialiased;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}

/* ---------- el taller ---------- */
.taller { position: fixed; inset: 0; width: 100%; height: 100%; }
.viñeta { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(120% 90% at 50% 45%, rgba(0,0,0,0) 45%, rgba(10,2,4,.65) 100%); }
.aurora { animation: aurora 9s ease-in-out infinite alternate; transform-origin: 540px 320px; }
@keyframes aurora { 0% { opacity: .55; transform: translateX(-30px) scaleY(.9); } 100% { opacity: 1; transform: translateX(30px) scaleY(1.15); } }
.estrellas circle { animation: titila 2.6s ease-in-out infinite; }
.estrellas circle:nth-child(2n) { animation-delay: 1.1s; }
@keyframes titila { 50% { opacity: .2; } }
.luces circle { animation: luz 1.8s steps(1) infinite; }
@keyframes luz { 50% { opacity: .35; filter: none; } }
.fuego { animation: fuego 2.2s ease-in-out infinite alternate; transform-origin: 540px 1250px; }
@keyframes fuego { from { opacity: .75; transform: scale(.97); } to { opacity: 1; transform: scale(1.04); } }
.paquetes { animation: cinta 16s linear infinite; }
@keyframes cinta { from { transform: translateX(0); } to { transform: translateX(-1080px); } }
.rodillos circle { transform-box: fill-box; transform-origin: center; }
.humo circle { animation: humo 3s ease-out infinite; }
.humo circle:nth-child(2) { animation-delay: 1.5s; }
@keyframes humo { from { opacity: .7; transform: translateY(0); } to { opacity: 0; transform: translateY(-40px); } }
.brillos circle { animation: brillo 4s ease-in-out infinite; }
@keyframes brillo { 0%, 100% { opacity: 0; } 50% { opacity: .9; } }

/* ---------- escena ---------- */
.escena {
  position: relative; z-index: 1; min-height: 100dvh; max-width: 640px; margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center;
}
.cabecera { line-height: 1; text-shadow: 0 3px 10px rgba(0,0,0,.5); }
.sobretitulo { margin: 0 0 6px; font: 600 clamp(15px, 3.8vw, 19px) 'Fredoka', sans-serif; color: var(--oro); letter-spacing: .1em; text-transform: uppercase; }
h1 { margin: 0; font: 700 clamp(30px, 8.5vw, 52px) 'Fredoka', sans-serif; }

.avatar { position: relative; width: min(52vw, 300px, 34vh); aspect-ratio: 1; display: grid; place-items: center; }
.avatar .aro { position: absolute; inset: -4%; border-radius: 50%; background: radial-gradient(circle, rgba(246,196,69,.35) 0%, rgba(246,196,69,0) 66%); transform: scale(var(--vol, 1)); transition: transform .08s linear; }
.elfo { position: relative; width: 88%; height: auto; filter: drop-shadow(0 12px 18px rgba(0,0,0,.45)); }
.elfo .boca { transform-origin: 100px 160px; transform: scaleY(var(--boca, 1)); }
.elfo .ojos { transform-origin: 100px 122px; animation: parpadeo 4.5s infinite; }
.elfo .cascabel { transform-origin: 186px 46px; }
@keyframes parpadeo { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
.zzz { position: absolute; top: 4%; right: 2%; font: 700 28px 'Fredoka', sans-serif; color: var(--suave); opacity: 0; }
.zzz span { font-size: .8em; margin-left: 2px; }
.avatar[data-estado="dormido"] .elfo { animation: respirar 3.5s ease-in-out infinite; }
.avatar[data-estado="dormido"] .ojos { animation: none; transform: scaleY(.12); }
.avatar[data-estado="dormido"] .boca { transform: scaleY(.45); }
.avatar[data-estado="dormido"] .zzz { animation: zzz 3s ease-in-out infinite; }
@keyframes zzz { 0% { opacity: 0; transform: translate(0, 10px); } 40% { opacity: .9; } 100% { opacity: 0; transform: translate(14px, -24px); } }
@keyframes respirar { 0%, 100% { transform: translateY(0) scale(1); } 50% { transform: translateY(4px) scale(.985); } }
.avatar[data-estado="sonando"] .elfo { animation: temblor .35s ease-in-out infinite; }
.avatar[data-estado="sonando"] .cascabel, .avatar[data-estado="hablando"] .cascabel { animation: cascabel .5s ease-in-out infinite; }
@keyframes temblor { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@keyframes cascabel { 0%, 100% { transform: rotate(-14deg); } 50% { transform: rotate(14deg); } }
.avatar[data-estado="hablando"] .elfo { animation: rebote .6s ease-in-out infinite; }
@keyframes rebote { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
.avatar[data-estado="escuchando"] .elfo { animation: escuchar 2.4s ease-in-out infinite; }
@keyframes escuchar { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-5deg); } }

.cartel {
  width: min(100%, 540px); padding: 10px 18px; border-radius: 18px; display: grid; gap: 4px;
  background: rgba(30, 6, 10, .62); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.subtitulo:empty { display: none; }
.estado { margin: 0; font: 700 clamp(19px, 4.8vw, 24px) 'Fredoka', sans-serif; text-shadow: 0 2px 8px rgba(0,0,0,.6); min-height: 1.3em; }
.subtitulo { margin: 0; font-size: 17px; font-weight: 700; color: var(--suave); text-shadow: 0 2px 6px rgba(0,0,0,.7); }

/* ---------- botones ---------- */
.controles { display: flex; flex-direction: column; align-items: center; gap: 12px; }
button { font: inherit; cursor: pointer; }
.boton-hablar {
  position: relative; width: min(46vw, 210px); aspect-ratio: 1; border-radius: 50%; border: 6px solid rgba(255,255,255,.85);
  background: radial-gradient(circle at 35% 30%, #45c97c, var(--verde) 70%); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font: 700 clamp(20px, 5vw, 26px) 'Fredoka', sans-serif; touch-action: none;
  box-shadow: 0 10px 0 rgba(0,0,0,.3), 0 18px 40px rgba(0,0,0,.45), 0 0 0 0 rgba(246,196,69,.6);
  transition: transform .08s, box-shadow .15s, background .2s;
}
.boton-hablar .icono svg { width: 54px; height: 54px; fill: currentColor; }
body[data-fase="reposo"] .boton-hablar { animation: latido 2s ease-in-out infinite; }
@keyframes latido { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }
body[data-fase="llamada"] .boton-hablar { background: radial-gradient(circle at 35% 30%, #ffd86b, #e0a21c 70%); color: #3a1a00; }
.boton-hablar.apretado, body[data-ptt="si"] .boton-hablar {
  transform: translateY(6px) scale(.97); background: radial-gradient(circle at 35% 30%, #ff6b7d, var(--rojo) 70%) !important; color: #fff !important;
  box-shadow: 0 4px 0 rgba(0,0,0,.3), 0 10px 26px rgba(0,0,0,.45), 0 0 0 18px rgba(255,107,125,.25);
}
.boton-hablar:disabled { opacity: .7; animation: none; }
.boton-cortar {
  min-height: 52px; padding: 0 28px; border-radius: 999px; border: 0; color: #fff;
  background: linear-gradient(180deg, #e63b51, var(--rojo2)); font: 700 20px 'Fredoka', sans-serif;
  box-shadow: 0 6px 0 rgba(0,0,0,.3);
}
.boton-cortar[hidden] { display: none; }
.ayuda { margin: 0; font-size: 14px; font-weight: 700; color: var(--suave); opacity: .9; }
kbd { font: 700 13px 'Nunito', sans-serif; padding: 2px 7px; border-radius: 6px; background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); }
.aviso { margin: 0; max-width: 440px; padding: 12px 16px; border-radius: 14px; background: rgba(215,38,61,.95); font-weight: 800; }
.aviso[hidden] { display: none; }

.ajustes {
  position: fixed; left: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 2;
  width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.3); color: var(--suave); font-size: 22px;
}
body:not([data-fase="reposo"]) .ajustes { display: none; }

dialog { width: min(460px, calc(100% - 24px)); border: 0; border-radius: 20px; padding: 0; background: #fff; color: #2a1a12; user-select: text; }
dialog::backdrop { background: rgba(20, 4, 6, .65); }
dialog form { padding: 22px; display: grid; gap: 16px; }
dialog h2 { margin: 0; font: 700 26px 'Fredoka', sans-serif; }
.campo-dlg { display: grid; gap: 6px; font-weight: 800; border: 0; margin: 0; padding: 0; }
.campo-dlg legend { padding: 0; margin-bottom: 6px; }
.campo-dlg small { font-weight: 600; color: #6b5548; }
.campo-dlg input[type=password], .campo-dlg input[type=text] { min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 2px solid #e5d6cc; font: 700 19px 'Nunito', sans-serif; }
.campo-dlg select { min-height: 48px; padding: 8px 12px; border-radius: 12px; border: 2px solid #e5d6cc; font: 700 16px 'Nunito', sans-serif; background: #fff; color: inherit; max-width: 100%; }
.campo-dlg input[type=range] { width: 100%; accent-color: var(--verde); }
.opcion { display: flex; gap: 10px; align-items: center; font-weight: 700; min-height: 36px; }
.opcion input { width: 20px; height: 20px; accent-color: var(--verde); }
dialog .acciones { display: flex; gap: 10px; justify-content: flex-end; }
dialog .acciones button { min-height: 46px; padding: 0 18px; border-radius: 12px; border: 2px solid #e5d6cc; background: #fff; font-weight: 800; }
dialog .acciones .principal { background: var(--verde); border-color: var(--verde); color: #fff; }

@media (max-height: 860px) and (min-width: 700px) {
  .escena { gap: 10px; }
  .avatar { width: min(30vh, 240px); }
  .boton-hablar { width: min(24vh, 180px); }
  .boton-hablar .icono svg { width: 42px; height: 42px; }
  h1 { font-size: 40px; }
}
@media (orientation: landscape) and (max-height: 700px) {
  .escena { max-width: 100%; display: grid; grid-template-columns: 1fr 1fr; grid-template-areas: "cab cab" "ava est" "ava sub" "ava ctl" "ava ayu"; column-gap: 24px; row-gap: 8px; }
  .cabecera { grid-area: cab; } .avatar { grid-area: ava; width: min(40vh, 300px); justify-self: end; }
  .escena { grid-template-areas: "cab cab" "ava est" "ava ctl" "ava ayu"; }
  .cartel { grid-area: est; } .controles { grid-area: ctl; } .ayuda { grid-area: ayu; }
  .boton-hablar { width: min(30vh, 170px); }
}
@media (hover: none) { .ayuda { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; } }
