:root {
  --noche: #14161c;
  --noche-2: #1d212b;
  --niebla: #9aa5b1;
  --madera: #6b4423;
  --madera-clara: #a0703c;
  --madera-oscura: #3e2714;
  --ambar: #f2a93b;
  --ambar-claro: #ffd27a;
  --musgo: #2f4a32;
  --musgo-claro: #4f7a4f;
  --sangre: #c0503a;
  --texto: #efe6d6;
  --texto-suave: #b9ad99;
  --radio: 14px;
  --verde: var(--verde);
  --rojo: var(--rojo);
  --cielo: #2b3342;
  --campo: rgba(10, 12, 16, .6);
  --borde-suave: rgba(239, 230, 214, .25);
  --chip: rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }

body {
  background: radial-gradient(ellipse at 70% -10%, var(--cielo) 0%, var(--noche) 60%) fixed, var(--noche);
  color: var(--texto);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

#app {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 24px;
}

h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; margin: 0 0 8px; }
h1 { font-size: 2.2rem; color: var(--ambar); text-shadow: 0 0 18px rgba(242, 169, 59, .35); letter-spacing: .5px; }
h2 { font-size: 1.4rem; color: var(--ambar-claro); }
p { line-height: 1.45; }
.suave { color: var(--texto-suave); }
.centro { text-align: center; }

.panel {
  background: linear-gradient(180deg, rgba(107, 68, 35, .28), rgba(62, 39, 20, .35));
  border: 1px solid rgba(160, 112, 60, .45);
  border-radius: var(--radio);
  padding: 14px;
  margin: 12px 0;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 210, 122, .08);
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px;
  border-radius: 12px; border: 1px solid rgba(0, 0, 0, .4);
  background: linear-gradient(180deg, var(--madera-clara), var(--madera));
  color: #fff7e8; font-weight: 700; font-size: 1rem;
  cursor: pointer; box-shadow: 0 3px 0 var(--madera-oscura);
  transition: transform .06s, filter .15s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--madera-oscura); }
.btn:disabled { filter: grayscale(.8) brightness(.6); cursor: not-allowed; }
.btn.ambar { background: linear-gradient(180deg, var(--ambar-claro), var(--ambar)); color: #2a1a08; box-shadow: 0 3px 0 #9a6516; }
.btn.musgo { background: linear-gradient(180deg, var(--musgo-claro), var(--musgo)); box-shadow: 0 3px 0 #1a2b1c; }
.btn.sangre { background: linear-gradient(180deg, #d9715c, var(--sangre)); box-shadow: 0 3px 0 #6e2a1d; }
.btn.fantasma { background: transparent; border-color: var(--borde-suave); box-shadow: none; color: var(--texto); }
.btn.bloque { width: 100%; }
.btn.peq { min-height: 38px; padding: 6px 12px; font-size: .9rem; }

.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila > .crece { flex: 1; }
.col { display: flex; flex-direction: column; gap: 10px; }

input[type="text"], select {
  width: 100%; min-height: 46px; padding: 8px 12px;
  border-radius: 10px; border: 1px solid rgba(160, 112, 60, .6);
  background: var(--campo); color: var(--texto); font-size: 1rem;
}
input:focus, select:focus { outline: 2px solid var(--ambar); outline-offset: 1px; }

/* Portada */
.portada { text-align: center; padding-top: 8px; }
.portada-img {
  display: block; width: 100%; height: auto; aspect-ratio: 1376 / 768; object-fit: cover;
  border-radius: var(--radio); border: 2px solid var(--madera-clara);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); margin-bottom: 14px;
}
.portada .burra { font-size: 64px; filter: drop-shadow(0 0 16px rgba(242, 169, 59, .4)); }

/* Lobby */
.jugador { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.avatar-btn {
  width: 50px; height: 50px; flex: none; font-size: 30px; border-radius: 50%;
  border: 2px solid var(--ambar); background: rgba(0, 0, 0, .35); cursor: pointer;
}
.corona { font-size: .75rem; color: var(--ambar); white-space: nowrap; }
.rejilla-avatares { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.rejilla-avatares button {
  font-size: 30px; aspect-ratio: 1; border-radius: 12px; cursor: pointer;
  border: 2px solid transparent; background: rgba(0, 0, 0, .3);
}
.rejilla-avatares button.sel { border-color: var(--ambar); background: rgba(242, 169, 59, .2); }
.rejilla-avatares button:disabled { opacity: .25; cursor: not-allowed; }

.contador { display: flex; align-items: center; gap: 12px; }
.contador b { font-size: 1.6rem; min-width: 2ch; text-align: center; color: var(--ambar); }

.segmentado { display: flex; border-radius: 12px; overflow: hidden; border: 1px solid rgba(160, 112, 60, .6); }
.segmentado button { flex: 1; min-height: 42px; background: transparent; color: var(--texto); border: 0; font-size: .95rem; cursor: pointer; }
.segmentado button.sel { background: var(--ambar); color: #2a1a08; font-weight: 700; }

/* Juego */
.cabecera { display: flex; justify-content: space-between; align-items: center; font-size: .9rem; color: var(--texto-suave); }
.pregunta { font-family: Georgia, serif; font-size: 1.25rem; line-height: 1.35; color: var(--texto); }
.etiqueta {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 700;
  background: var(--musgo); color: #dff0d8; text-transform: uppercase; letter-spacing: .5px;
}
.etiqueta.fecha { background: #4b3a6b; color: #e8dcff; }

.cifra-grande {
  font-size: 2.4rem; font-weight: 800; color: var(--ambar-claro); text-align: center;
  text-shadow: 0 0 20px rgba(242, 169, 59, .45); word-break: break-all; line-height: 1.1;
}
.cifra-sub { text-align: center; color: var(--texto-suave); font-size: .9rem; }

.temporizador { height: 12px; border-radius: 99px; background: rgba(0, 0, 0, .45); overflow: hidden; margin: 6px 0; }
.temporizador > div { height: 100%; background: linear-gradient(90deg, var(--sangre), var(--ambar)); transition: width .2s linear; }
.segundos { text-align: center; font-size: 2rem; font-weight: 800; }
.segundos.urgente { color: var(--sangre); animation: latido .5s infinite alternate; }
@keyframes latido { to { transform: scale(1.15); } }

.vista-previa { min-height: 1.4em; color: var(--ambar-claro); font-weight: 700; text-align: center; }
.botones-rapidos { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.pasajeros { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: rgba(0, 0, 0, .35); font-size: .9rem; }
.chip.conductor { background: rgba(242, 169, 59, .25); border: 1px solid var(--ambar); }
.chip.bajado { opacity: .55; text-decoration: line-through; }

.registro { font-size: .85rem; color: var(--texto-suave); max-height: 120px; overflow: auto; margin: 0; padding-left: 18px; }

.pasa-movil { text-align: center; padding: 30px 10px; }
.pasa-movil .gigante { font-size: 84px; }

/* Puente */
.escena { position: relative; border-radius: var(--radio); overflow: hidden; border: 1px solid rgba(160, 112, 60, .45); background: #0c0e13; }
.escena canvas { display: block; width: 100%; height: auto; }
.revelacion {
  position: absolute; left: 0; right: 0; top: 8px; text-align: center; pointer-events: none;
  font-weight: 800; font-size: 1.1rem; text-shadow: 0 2px 6px #000;
}
.resultado-titulo { font-size: 1.6rem; text-align: center; margin: 10px 0 4px; font-family: Georgia, serif; }
.resultado-titulo.ok { color: var(--verde); }
.resultado-titulo.ko { color: var(--rojo); }

table.puntos { width: 100%; border-collapse: collapse; }
table.puntos td { padding: 8px 4px; border-bottom: 1px solid rgba(160, 112, 60, .25); }
table.puntos td.num { text-align: right; font-weight: 800; }
.mas { color: var(--verde); }
.menos { color: var(--rojo); }

.podio { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 20px 0; }
.podio > div { text-align: center; width: 30%; }
.podio .peana { background: linear-gradient(180deg, var(--madera-clara), var(--madera-oscura)); border-radius: 8px 8px 0 0; color: #fff; font-weight: 800; padding-top: 6px; }
.podio .av { font-size: 40px; }

/* Anuncios */
.ad-banner {
  width: 100%; min-height: 56px; display: flex; align-items: center; justify-content: center;
  background: #0b0c10; border-top: 1px solid #2a2f3a; color: #59606e; font-size: .8rem;
  padding-bottom: env(safe-area-inset-bottom);
}
.ad-banner.oculto { display: none; }
.intersticial {
  position: fixed; inset: 0; background: rgba(5, 6, 9, .96); z-index: 50;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; text-align: center;
}
.intersticial .caja { width: min(360px, 100%); aspect-ratio: 3 / 4; border: 1px dashed #59606e; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: #59606e; }

/* Modal de avatares */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal .panel { width: min(420px, 100%); }

.reglas li { margin-bottom: 6px; }

/* Salas online */
.codigo {
  font-family: "Courier New", monospace; font-size: 3rem; font-weight: 800; letter-spacing: .35em;
  color: var(--ambar-claro); text-shadow: 0 0 18px rgba(242, 169, 59, .4); margin: 4px 0 12px; padding-left: .35em;
}
.codigo-input { text-transform: uppercase; letter-spacing: .3em; font-family: "Courier New", monospace; font-size: 1.4rem !important; text-align: center; margin-top: 6px; }
.enlace { font-size: .8rem; margin-top: 10px; word-break: break-all; user-select: all; }
.error { color: var(--rojo); min-height: 1.2em; font-weight: 700; }
.aviso { background: rgba(192, 80, 58, .25); border: 1px solid var(--sangre); border-radius: 10px; padding: 8px 12px; margin: 8px 0; font-size: .9rem; }
.ambar { color: var(--ambar); }
.chip.turno { outline: 2px solid var(--ambar-claro); animation: latido .6s infinite alternate; }
label { display: block; }

/* Avatares ilustrados */
.av { width: 1.6em; height: 1.6em; vertical-align: middle; border-radius: 50%; background: #2a2f3a; }
.av.grande { width: 100%; height: 100%; display: block; background: transparent; }
.av.gigante { width: 120px; height: 120px; border: 3px solid var(--ambar); box-shadow: 0 0 24px rgba(242, 169, 59, .35); }
.av-emoji.gigante { font-size: 84px; }
.avatar-btn { padding: 0; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; }
.rejilla-avatares button { padding: 2px; overflow: hidden; }
.podio-av { width: 64px; height: 64px; margin: 0 auto 4px; border-radius: 50%; overflow: hidden; border: 2px solid var(--ambar); background: #2a2f3a; font-size: 40px; display: flex; align-items: center; justify-content: center; }
.chip .av { width: 1.4em; height: 1.4em; }

/* Mini escena del turno: burra, carro y quién va dónde */
.rig { position: relative; border-radius: var(--radio); overflow: hidden; border: 1px solid rgba(160, 112, 60, .45); margin: 8px 0; }
.rig canvas { display: block; width: 100%; height: auto; aspect-ratio: 400 / 140; }
.rig-av { position: absolute; width: 10%; aspect-ratio: 1; transform: translate(-50%, -50%); }
.rig-av img { width: 100%; height: 100%; display: block; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .6)); }
.rig-av span { font-size: 22px; display: block; text-align: center; }
.rig-av.yo img { outline: 2px solid var(--ambar-claro); border-radius: 50%; }
.rig-salto.salta { animation: salto .7s ease-in-out; }
.rig-salto.bota { animation: bota .3s ease-in-out 3; }
@keyframes salto { 0% { transform: translateY(0); } 45% { transform: translateY(-70%) rotate(-12deg); } 100% { transform: translateY(0); } }
@keyframes bota { 50% { transform: translateY(-30%); } }

/* Iconos ilustrados de las opciones */
.ico { width: 1.7em; height: 1.7em; vertical-align: middle; flex: none; }
.btn .ico { width: 2em; height: 2em; margin: -6px 0; }
.chip .ico { width: 1.3em; height: 1.3em; }

/* Barra de ajustes: silencio y ⚙️ */
#app { padding-top: 56px; }
.barra-ajustes { position: fixed; top: 8px; right: max(8px, calc(50% - 272px)); z-index: 30; display: flex; gap: 6px; }
.btn-redondo {
  width: 40px; height: 40px; border-radius: 50%; font-size: 18px; cursor: pointer;
  border: 1px solid var(--borde-suave); background: var(--noche-2); color: var(--texto);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.modal .panel { background: var(--noche-2); }
.modal input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--ambar); }

/* Aviso de fallo (no se cierra el juego) */
.aviso-fallo {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%); z-index: 60; width: min(520px, calc(100% - 32px));
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: #3a1d17; color: #ffe3d9; border: 1px solid var(--sangre); border-radius: 12px; padding: 10px 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

/* Tema claro ("de día"): pergamino y madera */
:root[data-theme="light"] {
  --noche: #f3e9d6;
  --noche-2: #e8dcc4;
  --texto: #2b1d12;
  --texto-suave: #6b5a45;
  --ambar-claro: #a8650c;
  --verde: #2f7a3a;
  --rojo: #b23a26;
  --cielo: #fff6e4;
  --campo: rgba(255, 255, 255, .75);
  --borde-suave: rgba(43, 29, 18, .25);
  --chip: rgba(107, 68, 35, .12);
}
:root[data-theme="light"] .panel { background: linear-gradient(180deg, rgba(160, 112, 60, .16), rgba(107, 68, 35, .1)); }
:root[data-theme="light"] .chip { background: var(--chip); }
:root[data-theme="light"] .cifra-grande { text-shadow: none; }
:root[data-theme="light"] h1 { text-shadow: none; color: #b8731a; }
:root[data-theme="light"] .temporizador { background: rgba(107, 68, 35, .18); }
:root[data-theme="light"] .avatar-btn, :root[data-theme="light"] .rejilla-avatares button { background: rgba(107, 68, 35, .12); }
:root[data-theme="light"] .ad-banner { background: #e2d4b8; border-top-color: #cdbb98; color: #8a7a62; }

/* ¡Qué barbaridad! La abuela señala al que ha dicho un disparate */
.abuela-escena {
  position: fixed; inset: 0; z-index: 55; background: rgba(5, 6, 9, .94);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px;
  animation: aparece .25s ease-out;
}
.abuela-fila { display: flex; align-items: flex-end; gap: 6px; }
.abuela-cuerpo { position: relative; width: 140px; animation: entraAbuela .5s cubic-bezier(.3, 1.6, .5, 1); }
.abuela-cuerpo img { width: 140px; height: 140px; border-radius: 50%; border: 4px solid var(--ambar); background: #2a2f3a; }
.abuela-cuerpo .dedo { position: absolute; left: -26px; bottom: -22px; font-size: 44px; transform: rotate(125deg); animation: senala .35s ease-in-out infinite alternate; }
.abuela-bocadillo {
  position: relative; max-width: 200px; background: #fffaf0; color: #2b1d12; border: 3px solid #2b1d12; border-radius: 18px;
  padding: 10px 14px; font-family: Georgia, serif; font-weight: 800; font-size: 1.15rem; line-height: 1.25; margin-bottom: 70px;
  animation: entraBocadillo .4s .2s both cubic-bezier(.3, 1.6, .5, 1);
}
.abuela-bocadillo .palabra { opacity: .22; display: inline-block; transition: opacity .15s, transform .15s; }
.abuela-bocadillo .palabra.dicha { opacity: 1; animation: palabraDicha .3s cubic-bezier(.3, 1.8, .5, 1); }
@keyframes palabraDicha { from { transform: scale(1.35); color: #b3261e; } }
.abuela-bocadillo::after { content: ''; position: absolute; right: -16px; bottom: 14px; border: 10px solid transparent; border-left: 16px solid #2b1d12; }
.culpables { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; }
.culpable { display: flex; flex-direction: column; align-items: center; gap: 2px; color: #fff3e0; animation: tiembla .12s linear infinite; }
.culpable-av { width: 74px; height: 74px; border-radius: 50%; overflow: hidden; border: 3px solid var(--sangre); background: #2a2f3a; font-size: 48px; display: flex; align-items: center; justify-content: center; filter: saturate(1.4) hue-rotate(-10deg); }
.culpable span { font-size: .9rem; opacity: .85; }
.menos-uno { color: #ff8a73 !important; font-size: 1.6rem !important; font-weight: 900; opacity: 1 !important; animation: sube 1s .3s both; }
.abuela-escena .suave { color: #cdbfa8; }
.panel.barbaridades { border-color: var(--sangre); }
@keyframes aparece { from { opacity: 0; } }
@keyframes entraAbuela { from { transform: translateX(-120%) rotate(-20deg); } }
@keyframes entraBocadillo { from { transform: scale(0); } }
@keyframes senala { from { transform: rotate(118deg) translateX(0); } to { transform: rotate(128deg) translateX(8px); } }
@keyframes tiembla { 0% { transform: translateX(-1.5px); } 50% { transform: translateX(1.5px); } 100% { transform: translateX(-1.5px); } }
@keyframes sube { from { transform: translateY(14px); opacity: 0; } }

/* Valorar la pregunta */
.valorar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed rgba(160, 112, 60, .35);
}
.valorar .btn { font-size: 1.3rem; min-width: 48px; }

/* ¿Sabías que…? */
.aprende { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: var(--chip); border-left: 4px solid var(--ambar); }
.aprende-titulo { font-weight: 800; color: var(--ambar-claro); margin-bottom: 4px; }
.aprende p { margin: 0; line-height: 1.45; }
.aprende-img { float: right; margin: 2px 0 6px 10px; width: 38%; max-width: 160px; }
.aprende-img img { width: 100%; border-radius: 8px; display: block; background: #0002; }
.aprende-img figcaption { font-size: .7rem; opacity: .6; text-align: right; margin-top: 2px; }
.aprende::after { content: ''; display: block; clear: both; }
