/*
 * El Rosco 16:9 en celulares girados.
 * Mismas imágenes, paleta, letras, música y lógica del diseño vertical.
 * No toca el modo vertical.
 */
@media (orientation: landscape) and (min-width: 700px) and (max-width:1024px) and (max-height:600px) {
  body:not(.tvhost) .ext-shell.rr-abierta {
    overflow-x: hidden;
    overflow-y: auto;
  }
  body:not(.tvhost) .ext-shell.rr-abierta .ext-wrap {
    max-width: none;
    width: 100%;
  }
  body:not(.tvhost) .ext-shell.rr-abierta #extContenido {
    width: 100%;
    min-width: 0;
  }
  body:not(.tvhost) .ext-shell.rr-abierta .rr-game {
    max-width: 1460px;
    width: 100%;
    margin: 0 auto;
  }
  /* Ya existe el botón de regreso en la barra superior. */
  body:not(.tvhost) .rr-game > #rrVolver {
    display: none;
  }
  body:not(.tvhost) .rr-game[data-fase]:not([data-fase="inicio"]) .rr-titulo {
    display: none;
  }
  /* Tablero visible de una sola vez: HUD arriba, Rosco izquierdo,
     pista, mensaje y respuesta en la columna derecha. */
  body:not(.tvhost) .rr-game #rrJuego:not([hidden]) {
    display: grid;
    grid-template-columns: minmax(0, 0.96fr) minmax(0, 1fr);
    grid-template-rows: 42px 6px max-content minmax(18px,max-content) max-content minmax(0,1fr);
    gap: 8px 18px;
    width: 100%;
    height: max(235px,calc(var(--rr-viewport-alto,100dvh) - 62px));
    margin: 0 auto;
    min-width: 0;
    overflow: hidden;
  }
  body:not(.tvhost) .rr-game #rrJuego > .sf-hud {
    grid-column: 1 / -1;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    gap: 9px;
    width: 100%;
    max-width: none;
    margin: 0;
  }
  body:not(.tvhost) .rr-game #rrJuego > .sf-hud > div {
    min-height: 0;
    padding: 2px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  body:not(.tvhost) .rr-game #rrJuego > .sf-hud small {
    font-size: clamp(10px, 1.6vw, 14px);
    white-space: nowrap;
  }
  body:not(.tvhost) .rr-game #rrJuego > .sf-hud b {
    font-size: clamp(16px, 2.2vw, 26px);
  }
  body:not(.tvhost) .rr-game #rrJuego > .sf-bar {
    grid-column: 1 / -1;
    grid-row: 2;
    height: 6px;
    margin: 0;
  }
  body:not(.tvhost) .rr-game .rr-rueda {
    grid-column: 1;
    grid-row: 3 / -1;
    align-self: center;
    justify-self: center;
    width: min(44vw, calc(var(--rr-viewport-alto,100dvh) - 166px), 510px);
    max-width: 100%;
    margin: 0;
  }
  body:not(.tvhost) .rr-game .rr-letra {
    font-size: clamp(11px, 2.2vh, 19px);
  }
  body:not(.tvhost) .rr-game #rrGrande {
    font-size: clamp(42px, 12vh, 95px);
  }
  body:not(.tvhost) .rr-game .rr-pista {
    grid-column: 2;
    grid-row: 3;
    align-self: center;
    justify-self: stretch;
    min-width: 0;
    min-height: clamp(88px, 21dvh, 180px);
    padding: clamp(12px, 2vh, 22px);
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  body:not(.tvhost) .rr-game .rr-pista p {
    font-size: clamp(16px, 2.4vh, 23px);
    line-height: 1.32;
    overflow-wrap: anywhere;
  }
  body:not(.tvhost) .rr-game .rr-pista small {
    font-size: clamp(12px, 1.9vh, 17px);
  }
  body:not(.tvhost) .rr-game .rr-mensaje {
    grid-column: 2;
    grid-row: 4;
    align-self: center;
    margin: 0;
    min-height: 18px;
    font-size: clamp(12px, 1.7vh, 16px);
  }
  body:not(.tvhost) .rr-game #rrForm {
    grid-column: 2;
    grid-row: 5;
    width: 100%;
    min-width: 0;
    margin: 0 0 4px;
    align-self: end;
  }
  /* En Android el aviso nativo de pantalla completa aparece abajo.
     Subir la respuesta junto a la pista, no anclarla al borde inferior. */
  body:not(.tvhost) .rr-game #rrForm {
    align-self: start;
    margin-bottom: 0;
  }
  body:not(.tvhost) .rr-game .rr-pista {align-self:start}
  body:not(.tvhost) .rr-game .rr-fila {
    display: flex;
    align-items: stretch;
    gap: 9px;
  }
  body:not(.tvhost) .rr-game .rr-fila input {
    min-width: 0;
    flex: 1 1 0;
    width: 0;
    height: clamp(42px, 8dvh, 56px);
    padding: 8px 12px;
    font-size: clamp(14px, 2.3vh, 20px);
  }
  body:not(.tvhost) .rr-game .rr-fila button {
    min-height: 42px;
    padding-inline: clamp(10px, 1.8vw, 22px);
  }
  body:not(.tvhost) .rr-game .rr-fila #rrPasar {
    flex-direction: row;
    gap: 6px;
    font-size: clamp(11px, 1.8vh, 15px);
  }
  /* Inicio del Rosco: personaje a un lado, información + acciones al otro;
     el cartel y sus botones entran enteros sin hacer scroll vertical. */
  body:not(.tvhost) .rr-game[data-fase="inicio"] .rr-panel-capa {
    padding: 12px clamp(18px, 3vw, 50px);
  }
  body:not(.tvhost) .rr-game[data-fase="inicio"] .rr-panel {
    display: grid;
    grid-template-columns: minmax(125px, .37fr) minmax(0, 1fr);
    grid-auto-rows: min-content;
    align-items: center;
    column-gap: clamp(14px, 3vw, 34px);
    row-gap: clamp(5px, 1.15vh, 12px);
    width: min(100%, 1120px);
    max-height: calc(100dvh - 24px);
    padding: clamp(12px, 2.4vh, 24px);
    overflow: auto;
  }
  body:not(.tvhost) .rr-game[data-fase="inicio"] .rr-panel-dibujo {
    grid-column: 1;
    grid-row: 1 / span 6;
    align-self: center;
    justify-self: center;
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: min(60dvh, 310px);
    margin: 0;
  }
  body:not(.tvhost) .rr-game[data-fase="inicio"] .rr-panel > :is(h3,p,button) {
    grid-column: 2;
    min-width: 0;
    margin: 0;
  }
  body:not(.tvhost) .rr-game[data-fase="inicio"] .rr-panel h3 {
    font-size: clamp(18px, 3.3vh, 30px);
    line-height: 1.1;
  }
  body:not(.tvhost) .rr-game[data-fase="inicio"] .rr-panel p {
    font-size: clamp(12px, 1.9vh, 16px);
    line-height: 1.35;
    text-wrap: pretty;
  }
  body:not(.tvhost) .rr-game[data-fase="inicio"] .rr-panel button {
    min-height: clamp(34px, 7vh, 48px);
    padding: 7px 12px;
    font-size: clamp(12px, 2vh, 17px);
  }
  /* Resumen final en formato ancho, con desplazamiento limitado al resumen. */
  body:not(.tvhost) .rr-game[data-fase="fin"] .rr-panel {
    width: min(95vw, 850px);
    max-height: calc(100dvh - 30px);
    padding: 14px 20px;
  }
  body:not(.tvhost) .rr-game[data-fase="fin"] .rr-panel-dibujo {
    max-height: 16dvh;
    max-width: 130px;
  }
  body:not(.tvhost) .rr-game[data-fase="fin"] .rr-resumen {
    max-height: 21dvh;
  }
  body:not(.tvhost) .rr-game[data-fase="fin"] .rr-panel button {
    min-height: 34px;
    padding: 7px 10px;
    margin-top: 5px;
  }
}
/* El teclado Android tapa mucha pantalla en landscape. Cuando el usuario
   empieza a escribir, la vista de respuesta es prioritaria. */
@media (orientation:landscape) and (min-width:700px) and (max-width:1024px) and (max-height:600px) and (max-height:480px) {
  body:not(.tvhost) .rr-game #rrJuego:not([hidden]) {
    grid-template-rows: 35px 5px max-content 18px max-content minmax(0,1fr);
    gap:5px 12px;
  }
  body:not(.tvhost) .rr-game .rr-pista {padding:9px 12px}
  body:not(.tvhost) .rr-game .rr-pista p {font-size:clamp(13px,3.2vh,18px)}
  body:not(.tvhost) .rr-game .rr-fila input {height:41px}
    body:not(.tvhost) .rr-game #rrJuego > .sf-hud > div {padding:2px 5px;gap:5px}
  body:not(.tvhost) .rr-game #rrJuego > .sf-hud small {font-size:11px}
  body:not(.tvhost) .rr-game .rr-pista {min-height:80px}
}

/* Responder por voz en horizontal.
   Mantener botones, iconografía y paleta del Rosco original. */
.rr-game .rr-fila #rrVoz {display:none}
@media (orientation:landscape) and (min-width:700px) and (max-width:1024px) and (max-height:600px) {
  body:not(.tvhost) .rr-game .rr-fila #rrVoz {
    display:flex;
    flex:none;
    flex-direction:column;
    justify-content:center;
    align-items:center;
    gap:1px;
    min-width:clamp(55px,7vw,85px);
    padding:3px 6px;
    margin:0;
    background:#352146;
    border:1px solid #F5B30188;
    border-radius:12px;
    color:#F6EFE2;
    font-size:clamp(18px,3vh,24px);
    line-height:1;
  }
  body:not(.tvhost) .rr-game .rr-fila #rrVoz span {
    font-size:clamp(10px,1.5vh,13px);
    font-weight:900;
  }
  body:not(.tvhost) .rr-game .rr-fila #rrVoz.rr-grabando {
    background:#E5197C;
    border-color:#F5B301;
    box-shadow:0 0 0 2px #F5B30155;
    animation:rr-micro-latido 1s ease-in-out infinite alternate;
  }
  @keyframes rr-micro-latido {from {filter:brightness(.94)} to {filter:brightness(1.2)}}
  body:not(.tvhost) .rr-game .rr-fila #rrPasar {
    max-width:clamp(95px,13vw,160px);
    padding:4px 6px;
  }
  body:not(.tvhost) .rr-game .rr-fila #rrPasar .rr-ico {
    width:clamp(17px,3vh,23px);
    height:clamp(17px,3vh,23px);
  }
  /* Al aparecer el teclado Android, ocultar el círculo y la cabecera
     TEMPORALMENTE. Mostrar pista y formulario dentro del visualViewport.
     Al cerrar teclado regresa automáticamente la composición 16:9. */
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto {
    overflow:hidden;
    padding:0 max(6px,env(safe-area-inset-right,0px)) 0 max(6px,env(safe-area-inset-left,0px));
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .ext-header,
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-titulo,
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game > #rrVolver {
    display:none!important;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto :is(.ext-wrap,#extContenido,.rr-game) {
    max-width:none;
    width:100%;
    margin:0;
    padding:0;
    min-height:0;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game #rrJuego:not([hidden]) {
    display:flex!important;
    flex-direction:column;
    justify-content:flex-start;
    align-items:stretch;
    width:100%;
    height:var(--rr-viewport-alto,150px);
    max-height:var(--rr-viewport-alto,150px);
    min-height:0;
    margin:0;
    gap:3px;
    overflow:hidden;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto #rrJuego > :is(.sf-hud,.sf-bar,.rr-rueda,.rr-mensaje) {
    display:none!important;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-pista {
    display:flex;
    flex:0 1 auto;
    order:0;
    min-height:0;
    max-height:calc(var(--rr-viewport-alto,150px) - 50px);
    overflow:hidden;
    justify-content:center;
    padding:3px 9px;
    margin:0;
    border-radius:9px;
    line-height:1.1;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-pista .voz-fila {
    min-height:0;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-pista :is(.rr-pista-ico,.rr-escuchar) {
    display:none!important;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-pista small {
    font-size:11px;
    line-height:1.1;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-pista p {
    margin:1px 0 0;
    font-size:clamp(11px,2.5dvh,14px);
    line-height:1.15;
    max-height:2.3em;
    overflow:hidden;
    display:-webkit-box;
    -webkit-line-clamp:2;
    -webkit-box-orient:vertical;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game #rrForm {
    display:block;
    flex:0 0 auto;
    order:1;
    align-self:stretch;
    width:100%;
    min-width:0;
    margin:0;
    padding:0;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-fila {
    display:flex;
    flex-wrap:nowrap;
    align-items:center;
    gap:5px;
    height:clamp(35px,7dvh,44px);
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-fila input {
    width:0;
    flex:1 1 auto;
    min-width:65px;
    height:100%;
    margin:0;
    padding:4px 9px;
    border-radius:9px;
    font-size:16px;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-fila button {
    min-height:100%;
    max-height:100%;
    padding:2px 6px;
    margin:0;
    border-radius:9px;
    font-size:12px;
    flex:0 0 auto;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-fila #rrVoz {
    min-width:50px;
    font-size:16px;
  }
  body:not(.tvhost) .ext-shell.rr-abierta.rr-teclado-abierto .rr-game .rr-fila #rrVoz span {
    font-size:10px;
  }
}


/* Selector de prueba heredado: Gonzalo y Vale al utilizar TV horizontal. */
.rr-game.rr-gonzalo .rr-teclado-g{display:none}
.rr-game.rr-gonzalo .rr-estado-voz-g{display:none;color:#37D6C0;font-size:11px;font-weight:800;margin:2px 0 4px;min-height:14px}
.rr-game.rr-gonzalo.rr-con-voz .rr-estado-voz-g{display:block}
.rr-game.rr-gonzalo .rr-teclas-fila{display:flex;justify-content:center;gap:3px}
.rr-game.rr-gonzalo .rr-tecla-g{
  display:block;flex:1;min-width:0;min-height:33px;padding:4px 2px;
  border-radius:6px;background:#56406D;color:#fff;border:1px solid #A58FBF66;
  font:900 clamp(12px,1.75vw,17px) system-ui,sans-serif;
}
.rr-game.rr-gonzalo .rr-tecla-g:active{background:#E5197C}
.rr-game.rr-gonzalo .rr-tecla-g.rr-tecla-accion{background:#352146}
@media (orientation:landscape) and (min-width:700px) and (max-width:1024px) and (max-height:600px){
  .rr-game.rr-gonzalo #rrJuego:not([hidden]){
    grid-template-columns:minmax(0,.84fr) minmax(0,1.16fr);
    grid-template-rows:32px 5px minmax(40px,max-content) minmax(15px,max-content) minmax(42px,max-content) max-content max-content;
    gap:4px 10px;height:auto;overflow:visible;min-width:0;
  }
  .rr-game.rr-gonzalo #rrJuego .rr-rueda{grid-row:3 / span 5;width:min(47vh,33vw,285px)}
  .rr-game.rr-gonzalo #rrJuego .rr-pista{grid-row:3;min-height:55px;max-height:95px;padding:6px 9px}
  .rr-game.rr-gonzalo #rrJuego .rr-pista p{font-size:clamp(12px,3.3vh,16px);line-height:1.23}
  .rr-game.rr-gonzalo #rrJuego #rrForm{grid-row:5}
  .rr-game.rr-gonzalo #rrJuego .rr-mensaje{grid-row:4;font-size:12px;line-height:1.2}
  .rr-game.rr-gonzalo #rrJuego .rr-teclado-g{
    grid-column:2;grid-row:6;display:grid;gap:4px;margin:0;
    padding:7px;border-radius:11px;background:#29193D;border:1px solid #F5B30155
  }
  .rr-game.rr-gonzalo #rrJuego .rr-estado-voz-g{grid-column:2;grid-row:7}
  .rr-game.rr-gonzalo .rr-tecla-g{min-height:clamp(34px,9vh,42px)}
  .rr-game.rr-gonzalo.rr-con-voz #rrJuego .rr-teclado-g{display:none}
  .rr-game.rr-gonzalo .rr-fila input{height:40px;font-size:15px}
  .rr-game.rr-gonzalo .rr-fila button{min-height:40px;padding:4px 7px}
  .rr-game.rr-gonzalo .rr-fila #rrVoz{display:flex}
  .rr-game.rr-gonzalo[data-fase="inicio"] .rr-panel button{min-height:30px}
}


/* Rosco en celular vertical: botón Hablar con el mismo modo de voz que
   funciona en horizontal, sin abrir Gboard cuando está escuchando.
   Prueba limitada al perfil Gonzalo; no afecta a otros jugadores. */
@media (orientation:portrait) and (max-width:700px){
  .rr-game.rr-gonzalo #rrForm .rr-fila{
    display:grid;grid-template-columns:repeat(3,minmax(0,1fr));
    gap:6px;align-items:stretch;width:100%;min-width:0;
  }
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrEntrada{
    grid-column:1 / -1;grid-row:1;
    width:100%;min-width:0;min-height:43px;height:43px;
    box-sizing:border-box;padding:8px 12px;margin:0;
    font-size:16px;
  }
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrEnviar,
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrPasar,
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrVoz{
    width:100%;min-width:0;min-height:44px;height:44px;
    box-sizing:border-box;margin:0;padding:4px 6px;
    font-size:clamp(10px,3vw,13px);line-height:1.1;
  }
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrEnviar{grid-column:1;grid-row:2}
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrPasar{
    grid-column:2;grid-row:2;display:flex;flex-direction:row;
    gap:3px;align-items:center;justify-content:center;
  }
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrPasar .rr-ico{width:19px;height:19px}
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrVoz{
    grid-column:3;grid-row:2;display:flex;
    flex-direction:row;align-items:center;justify-content:center;gap:4px;
    background:#352146;border:1px solid #F5B30188;
    color:#F6EFE2;font-size:18px;
  }
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrVoz span{
    font:900 12px Outfit,system-ui,sans-serif;
  }
  .rr-game.rr-gonzalo #rrForm .rr-fila #rrVoz.rr-grabando{
    background:#E5197C;border-color:#F5B301;
    box-shadow:0 0 0 2px #F5B30155;
  }
  .rr-game.rr-gonzalo.rr-con-voz .rr-estado-voz-g{
    display:block;font-size:12px;line-height:1.3;
    text-align:center;max-width:100%;margin:5px 0 2px;
  }
  .rr-game.rr-gonzalo.rr-con-voz #rrEntrada{
    opacity:.85;pointer-events:none;
  }
}

/* Activación opcional de voz en Rosco horizontal; no se muestra a otros perfiles. */
.rr-game .rr-voz-consulta{
  position:fixed;inset:0;z-index:110;display:grid;place-items:center;
  background:#0b061bdc;padding:12px max(12px,env(safe-area-inset-right,0px)) 12px max(12px,env(safe-area-inset-left,0px));
}
.rr-game .rr-voz-consulta-caja{
  box-sizing:border-box;width:min(100%,440px);max-height:calc(100dvh - 24px);overflow:auto;
  padding:15px 17px;border:2px solid #37D6C0;border-radius:16px;
  background:#29193d;color:#f6efe2;text-align:center;box-shadow:0 12px 32px #0009;
}
.rr-game .rr-voz-consulta h3{font-size:clamp(16px,4dvh,22px);color:#f5b301;margin:0 0 8px}
.rr-game .rr-voz-consulta p{font-size:clamp(12px,3dvh,15px);line-height:1.3;margin:0 0 12px}
.rr-game .rr-voz-consulta-acciones{display:flex;gap:8px}
.rr-game .rr-voz-consulta-acciones button{
  flex:1;min-width:0;border:1px solid #796a99;border-radius:10px;
  background:#3d2b55;color:white;min-height:40px;padding:8px;font-weight:900;
}
.rr-game .rr-voz-consulta-acciones [data-voz="si"]{background:#116c62;border-color:#37d6c0}
@media (orientation:landscape) and (max-height:350px){
  .rr-game .rr-voz-consulta-caja{padding:8px 12px}
  .rr-game .rr-voz-consulta p{margin-bottom:6px}
  .rr-game .rr-voz-consulta-acciones button{min-height:32px}
}

/* Margen de seguridad del teclado a la derecha al duplicar pantalla.
   También vale con rotación manual; no altera el Rosco vertical. */
@media (orientation:landscape) and (min-width:700px) and (max-width:1024px) and (max-height:600px){
  body:not(.tvhost) .ext-shell.rr-abierta .rr-game #rrJuego:not([hidden]){
    box-sizing:border-box;
    padding-right:max(20px,env(safe-area-inset-right,0px));
  }
}
/* En celulares horizontales bajos, conservar visible la cuarta fila
   del teclado del Rosco sin afectar las teclas del modo vertical. */
@media (orientation:landscape) and (min-width:700px) and (max-width:1024px) and (max-height:400px){
  body:not(.tvhost) .rr-game.rr-gonzalo #rrJuego .rr-teclado-g{
    gap:3px;
    padding:5px;
  }
  body:not(.tvhost) .rr-game.rr-gonzalo #rrJuego .rr-tecla-g{
    min-height:31px;
  }
}
