/* Rune Rush Rage — pantalla de controles: una plana de Orsen.
   Papel con renglones y margen rojo, tinta y letra Spectral, como el atril.
   Todo se mide en em y la letra crece con la ventana igual que el atril:
   16 px a 1280×720 y 24 px a 1920×1080. Se monta en <body>, por encima de #ui-root. */

.rrr-controles {
  --ctl-papel: #ece1c9;
  --ctl-papel-claro: #f3e9d4;
  --ctl-papel-borde: #d6c6a2;
  --ctl-tinta: #1e1815;
  --ctl-tinta-suave: #4f4034;
  --ctl-tinta-tenue: rgba(30, 24, 21, 0.18);
  --ctl-renglon: rgba(52, 66, 84, 0.26);
  --ctl-rojo: #9e2030;
  --ctl-ambar: #ffb347;
  --ctl-turq: #2ee6d6;
  --ctl-turq-tinta: #0d6a63;
  --ctl-letra-titulo: 'Cinzel', 'Palatino Linotype', 'Book Antiqua', Georgia, serif;
  --ctl-letra: 'Spectral', 'Palatino Linotype', Georgia, serif;
  --ctl-grano: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)' opacity='0.11'/%3E%3C/svg%3E");
  /* Aguada turquesa del foco (la misma del atril) */
  --ctl-aguada: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 60' preserveAspectRatio='none'%3E%3Cpath d='M5 21C22 7 70 4 120 6S186 3 196 12C199 24 197 38 192 50C150 57 96 55 52 57S8 55 4 44C1 36 2 28 5 21Z' fill='%232ee6d6' fill-opacity='.5'/%3E%3Cpath d='M14 18C60 10 130 12 188 15' stroke='%232ee6d6' stroke-opacity='.35' stroke-width='3' fill='none'/%3E%3C/svg%3E");
  /* Aguada ámbar mientras espera la tecla */
  --ctl-aguada-ambar: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 60' preserveAspectRatio='none'%3E%3Cpath d='M7 18C30 6 78 5 126 7S188 6 195 15C198 27 196 40 190 49C146 56 98 54 54 56S9 54 5 43C2 34 3 26 7 18Z' fill='%23ffb347' fill-opacity='.55'/%3E%3Cpath d='M16 46C62 50 124 49 184 45' stroke='%239a5410' stroke-opacity='.3' stroke-width='2.5' fill='none'/%3E%3C/svg%3E");
  /* Teclas dibujadas a pluma: cuatro trazos que se pasan en las esquinas y un repaso más claro.
     Tres variantes para que no salgan todas iguales. */
  --ctl-tecla-0: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M4 7C30 5.6 64 6.2 96 5.2M95 4C95.8 15 95.4 26 96 36.6' fill='none' stroke='%231e1815' stroke-opacity='.2' stroke-width='1.1' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3Cpath d='M2.5 5.5C28 3.8 66 4.6 97.8 3.4M96.4 1.8C97.4 13 96.8 27 97.6 38.2M98.8 36.4C68 37.6 33 36.2 1.4 37.4M3.6 39C2.4 27 3.4 13 2.2 2.4' fill='none' stroke='%231e1815' stroke-opacity='.82' stroke-width='1.55' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  --ctl-tecla-1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M3 35C30 36 66 35.4 96 34.4M4.6 36.8C5 26 4 15 4.8 4' fill='none' stroke='%231e1815' stroke-opacity='.2' stroke-width='1.1' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3Cpath d='M1.6 4.2C34 5.2 70 3.2 98.6 4.8M97.2 2.6C98 15 96.6 26 97.4 37.2M99 35.6C64 36.8 30 37.8 2 36.2M3 38.4C3.6 25 2.2 14 3.2 2' fill='none' stroke='%231e1815' stroke-opacity='.82' stroke-width='1.55' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  --ctl-tecla-2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 40' preserveAspectRatio='none'%3E%3Cpath d='M5 6.2C32 7 60 5.2 94.6 7M6.2 37C5 26 5.8 16 4.8 5.4' fill='none' stroke='%231e1815' stroke-opacity='.2' stroke-width='1.1' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3Cpath d='M3 3.8C30 5 62 3 97 5.4M95.6 3C96.8 14 98 25 96.8 38.6M98.2 37C70 35.6 36 37.2 2.2 36.6M4.2 38.8C2.8 27 3.8 15 2.6 3.2' fill='none' stroke='%231e1815' stroke-opacity='.82' stroke-width='1.55' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  /* Círculo rojo de corrección, abierto como lo cierra una mano con prisa */
  --ctl-circulo-rojo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 50' preserveAspectRatio='none'%3E%3Cpath d='M70 4C38 1 7 9 4 25C2 40 34 48 66 46C96 44 117 36 116 22C115 10 92 3 61 5C52 6 44 7 38 9' fill='none' stroke='%239e2030' stroke-opacity='.85' stroke-width='2' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  /* Subrayado rojo ondulado bajo la corrección */
  --ctl-subrayado-rojo: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 10' preserveAspectRatio='none'%3E%3Cpath d='M2 6C30 3 52 8 80 5S130 3 160 6S220 8 250 4S286 5 298 6' fill='none' stroke='%239e2030' stroke-opacity='.6' stroke-width='1.6' stroke-linecap='round' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");
  /* Doble línea roja del margen, trazada a mano */
  --ctl-margen: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 400' preserveAspectRatio='none'%3E%3Cpath d='M2.6 0C2.2 90 3.1 190 2.4 280S2.9 360 2.7 400M7.4 0C7.8 100 7 200 7.6 300S7.2 370 7.5 400' fill='none' stroke='%239e2030' stroke-opacity='.5' stroke-width='1.2' vector-effect='non-scaling-stroke'/%3E%3C/svg%3E");

  font-size: min(1.25vw, 2.2222vh);
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  background: rgba(8, 6, 11, 0.78);
  pointer-events: auto;
  outline: none;
  user-select: none;
  animation: rrr-ctl-aparece 180ms ease-out;
}

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

/* --- La hoja ------------------------------------------------------------------- */
.rrr-ctl-hoja {
  position: relative;
  width: 41.5em;
  max-width: 98vw;
  max-height: calc(100vh - 0.6em);
  overflow: auto;
  scrollbar-width: none;
  padding: 1em 2em 0.85em 4.6em;
  color: var(--ctl-tinta);
  font-family: var(--ctl-letra);
  background-color: var(--ctl-papel);
  background-image:
    var(--ctl-grano),
    radial-gradient(ellipse 70% 60% at 40% 38%, var(--ctl-papel-claro) 0%, transparent 72%),
    radial-gradient(ellipse 40% 30% at 88% 92%, rgba(150, 118, 78, 0.16) 0%, transparent 70%),
    linear-gradient(90deg, var(--ctl-papel-borde) 0%, transparent 3%, transparent 97%, var(--ctl-papel-borde) 100%);
  box-shadow:
    0 1.4em 3.6em rgba(0, 0, 0, 0.8),
    inset 0 0 2.6em rgba(89, 73, 59, 0.24);
  /* Bordes de papel cortado a mano */
  clip-path: polygon(0.3% 0.8%, 31% 0.2%, 62% 0.9%, 99.6% 0.3%, 99.9% 38%, 99.4% 71%, 99.8% 99.5%, 64% 99.1%, 28% 99.8%, 0.4% 99.2%, 0.1% 63%, 0.6% 27%);
  animation: rrr-ctl-hoja 220ms ease-out;
}

.rrr-ctl-hoja::-webkit-scrollbar {
  display: none;
}

/* Margen rojo de las planas, donde Orsen escribía sus correcciones */
.rrr-ctl-margen {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 3.15em;
  width: 0.62em;
  background: var(--ctl-margen) center / 100% 100% no-repeat;
  pointer-events: none;
}

.rrr-ctl-cabeza {
  padding-bottom: 0.3em;
}

.rrr-ctl-titulo {
  margin: 0;
  font-family: var(--ctl-letra-titulo);
  font-size: 1.32em;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ctl-tinta);
  line-height: 1.15;
}

.rrr-ctl-nota {
  margin: 0.15em 0 0;
  font-size: 0.82em;
  font-style: italic;
  line-height: 1.3;
  color: var(--ctl-tinta-suave);
}

/* --- Renglones ----------------------------------------------------------------- */
.rrr-ctl-tabla {
  display: flex;
  flex-direction: column;
}

.rrr-ctl-fila {
  display: grid;
  grid-template-columns: 8.6em repeat(3, 7.3em);
  column-gap: 1em;
  align-items: end;
  height: 2.12em;
  /* El renglón cruza la hoja entera, margen incluido */
  margin: 0 -2em 0 -4.6em;
  padding: 0 2em 0.12em 4.6em;
  background: linear-gradient(to top, transparent 0, transparent 0.06em, var(--ctl-renglon) 0.06em, var(--ctl-renglon) calc(0.06em + 1px), transparent calc(0.06em + 1px)) bottom / 100% 100% no-repeat;
}

.rrr-ctl-fila--cab {
  height: 1.6em;
  background: none;
}

.rrr-ctl-colcab {
  justify-self: center;
  font-size: 0.8em;
  font-style: italic;
  color: var(--ctl-tinta-suave);
  line-height: 1;
  padding-bottom: 0.2em;
}

.rrr-ctl-accion {
  font-size: 1em;
  line-height: 1.2;
  padding-bottom: 0.18em;
  white-space: nowrap;
  color: var(--ctl-tinta);
}

/* --- Casillas ------------------------------------------------------------------ */
.rrr-ctl-casilla {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 1.78em;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ctl-tinta);
  font-family: var(--ctl-letra);
  font-size: 1em;
  cursor: pointer;
  outline: none;
}

/* Envoltorio de la tecla: lleva la aguada del foco detrás y el círculo rojo delante */
.rrr-ctl-marca {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.rrr-ctl-marca::before {
  content: '';
  position: absolute;
  inset: -0.32em -0.8em;
  z-index: 0;
  background: var(--ctl-aguada) center / 100% 100% no-repeat;
  opacity: 0;
  transition: opacity 120ms ease;
  pointer-events: none;
}

.rrr-ctl-casilla.is-foco .rrr-ctl-marca::before {
  opacity: 1;
}

.rrr-ctl-casilla.is-capturando .rrr-ctl-marca::before {
  background-image: var(--ctl-aguada-ambar);
  opacity: 1;
  animation: rrr-ctl-respira 1.4s ease-in-out infinite;
}

/* Círculo rojo de Orsen en la casilla que ha cambiado por un intercambio */
.rrr-ctl-marca::after {
  content: '';
  position: absolute;
  inset: -0.5em -0.75em -0.45em -0.85em;
  z-index: 2;
  background: var(--ctl-circulo-rojo) center / 100% 100% no-repeat;
  opacity: 0;
  transform: scale(1.12) rotate(-3deg);
  transition: opacity 700ms ease, transform 300ms ease;
  pointer-events: none;
}

.rrr-ctl-casilla.is-corregida .rrr-ctl-marca::after {
  opacity: 1;
  transform: scale(1) rotate(-3deg);
  transition-duration: 160ms, 220ms;
}

.rrr-ctl-tecla {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.15em;
  min-width: 2.3em;
  height: 1.42em;
  padding: 0 0.5em;
  font-size: 0.98em;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

/* El contorno de la tecla va aparte para poder torcerlo un poco sin torcer la letra */
.rrr-ctl-tecla::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--ctl-tecla-0) center / 100% 100% no-repeat;
  transform: rotate(-0.7deg);
  pointer-events: none;
}

.rrr-ctl-casilla[data-variante='1'] .rrr-ctl-tecla::before {
  background-image: var(--ctl-tecla-1);
  transform: rotate(0.6deg);
}

.rrr-ctl-casilla[data-variante='2'] .rrr-ctl-tecla::before {
  background-image: var(--ctl-tecla-2);
  transform: rotate(-0.25deg);
}

/* Casilla vacía: un hueco para rellenar, punteado como en las planas */
.rrr-ctl-casilla.is-vacia .rrr-ctl-tecla {
  min-width: 3.4em;
  height: 1.1em;
  border-bottom: 1.5px dotted rgba(30, 24, 21, 0.38);
}

.rrr-ctl-casilla.is-vacia .rrr-ctl-tecla::before,
.rrr-ctl-casilla.is-capturando .rrr-ctl-tecla::before {
  display: none;
}

/* Esc de la pausa: fija */
.rrr-ctl-casilla.is-fija {
  cursor: default;
}

.rrr-ctl-casilla.is-fija .rrr-ctl-tecla {
  color: var(--ctl-tinta-suave);
}

.rrr-ctl-fija {
  position: relative;
  z-index: 1;
  margin-left: 0.32em;
  font-size: 0.72em;
  font-style: italic;
  color: var(--ctl-tinta-suave);
}

/* Esperando la tecla: el texto se aparta y queda la pluma parpadeando */
.rrr-ctl-casilla.is-capturando .rrr-ctl-tecla {
  color: transparent;
  border-bottom: 1.5px dotted rgba(30, 24, 21, 0.45);
  min-width: 3.4em;
  height: 1.1em;
}

.rrr-ctl-casilla.is-capturando .rrr-ctl-tecla::after {
  content: '';
  position: absolute;
  left: 50%;
  top: -0.05em;
  bottom: 0.08em;
  width: 0.13em;
  margin-left: -0.065em;
  border-radius: 0.1em;
  background: var(--ctl-tinta);
  animation: rrr-ctl-pluma 0.9s steps(2, jump-none) infinite;
}

/* Tinta recién puesta */
.rrr-ctl-casilla.is-fresca .rrr-ctl-tecla {
  animation: rrr-ctl-tinta 700ms ease-out;
}

.rrr-ctl-flecha-wrap {
  display: inline-flex;
  align-items: center;
}

.rrr-ctl-flecha {
  width: 1.05em;
  height: 1.05em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --- Línea de avisos ----------------------------------------------------------- */
.rrr-ctl-linea {
  margin: 0.5em 0 0;
  min-height: 1.55em;
  font-size: 0.95em;
  line-height: 1.4;
  font-style: italic;
  color: var(--ctl-tinta-suave);
}

.rrr-ctl-linea.is-captura {
  color: var(--ctl-tinta);
}

.rrr-ctl-linea.is-aviso,
.rrr-ctl-linea.is-error {
  color: var(--ctl-rojo);
}

/* La corrección del intercambio va subrayada en rojo, como las planas */
.rrr-ctl-linea.is-aviso {
  display: inline-block;
  padding-bottom: 0.1em;
  background: var(--ctl-subrayado-rojo) left bottom / 100% 0.42em no-repeat;
  animation: rrr-ctl-tinta 600ms ease-out;
}

.rrr-ctl-linea .rrr-ctl-flecha {
  width: 0.95em;
  height: 0.95em;
  vertical-align: -0.12em;
}

/* --- Pie: atajos y botones ----------------------------------------------------- */
.rrr-ctl-pie {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  column-gap: 1.2em;
  margin-top: 0.45em;
  padding-top: 0.35em;
  border-top: 1px solid var(--ctl-tinta-tenue);
}

.rrr-ctl-ayudas {
  font-size: 0.74em;
  line-height: 1.38;
  color: var(--ctl-tinta);
}

.rrr-ctl-ayuda {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  column-gap: 1em;
}

.rrr-ctl-ayuda-quien {
  min-width: 4.8em;
  font-family: var(--ctl-letra-titulo);
  font-size: 0.92em;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ctl-tinta-suave);
}

.rrr-ctl-ayuda-par {
  white-space: nowrap;
}

.rrr-ctl-ayuda kbd {
  display: inline-flex;
  align-items: baseline;
  font-family: inherit;
  font-size: 1em;
  font-weight: 700;
  color: var(--ctl-tinta);
}

.rrr-ctl-ayuda .rrr-ctl-flecha {
  width: 0.95em;
  height: 0.95em;
  align-self: center;
}

.rrr-ctl-botones {
  display: flex;
  flex-direction: column;
  gap: 0.3em;
  width: 8.2em;
}

.rrr-ctl-boton {
  appearance: none;
  -webkit-appearance: none;
  padding: 0.32em 0.8em;
  border: 1.5px solid var(--ctl-tinta);
  background: var(--ctl-tinta);
  color: var(--ctl-papel);
  font-family: var(--ctl-letra);
  font-size: 0.86em;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  clip-path: polygon(1% 4%, 99% 0%, 98% 96%, 0.5% 100%);
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.rrr-ctl-boton.is-foco {
  background: var(--ctl-turq-tinta);
  border-color: var(--ctl-turq-tinta);
}

.rrr-ctl-boton--claro {
  border-color: transparent;
  background: var(--ctl-tecla-1) center / 100% 100% no-repeat;
  color: var(--ctl-tinta);
  clip-path: none;
}

.rrr-ctl-boton--claro.is-foco {
  background:
    var(--ctl-tecla-1) center / 100% 100% no-repeat,
    var(--ctl-aguada) center / 100% 100% no-repeat;
  border-color: transparent;
  color: var(--ctl-tinta);
}

/* --- Animaciones --------------------------------------------------------------- */
@keyframes rrr-ctl-aparece {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes rrr-ctl-hoja {
  from {
    transform: translateY(0.6em);
  }
  to {
    transform: none;
  }
}

@keyframes rrr-ctl-respira {
  0%,
  100% {
    opacity: 0.75;
  }
  50% {
    opacity: 1;
  }
}

@keyframes rrr-ctl-pluma {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@keyframes rrr-ctl-tinta {
  0% {
    opacity: 0.2;
    filter: blur(0.6px);
  }
  100% {
    opacity: 1;
    filter: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rrr-controles,
  .rrr-ctl-hoja,
  .rrr-ctl-casilla.is-capturando .rrr-ctl-marca::before,
  .rrr-ctl-casilla.is-fresca .rrr-ctl-tecla,
  .rrr-ctl-linea.is-aviso {
    animation: none;
  }
  .rrr-ctl-casilla.is-capturando .rrr-ctl-tecla::after {
    animation: none;
  }
}

/* Ventanas estrechas */
@media (max-aspect-ratio: 4/3) and (max-width: 900px) {
  .rrr-controles {
    font-size: min(2vw, 2.2222vh);
  }
}

@media (max-width: 640px) {
  .rrr-controles {
    font-size: 11px;
  }
  .rrr-ctl-hoja {
    padding-left: 3.6em;
  }
  .rrr-ctl-margen {
    left: 2.4em;
  }
  .rrr-ctl-fila {
    grid-template-columns: 7em repeat(3, 6.2em);
    column-gap: 0.6em;
    margin-left: -3.6em;
    padding-left: 3.6em;
  }
  .rrr-ctl-pie {
    grid-template-columns: 1fr;
    row-gap: 0.6em;
  }
  .rrr-ctl-botones {
    flex-direction: row;
    width: auto;
  }
}
