/* === Fuentes locales (sistema consola davs) === */
@font-face {
  font-family: 'VT323';
  src: url('../assets/fonts/vt323-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Silkscreen';
  src: url('../assets/fonts/silkscreen-latin-400-normal.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Silkscreen';
  src: url('../assets/fonts/silkscreen-latin-700-normal.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

/* === Tokens del sistema (tema CIAN — theme.ts de la consola) === */
:root {
  /* VT323 es alta/estrecha: ensanche sintético de la letra de serie
     (no hay fuente más ancha en el sistema de la consola) */
  --ui-ensanche: 1.12;
  --ui-principal: #33FF66;
  --ui-tenue: rgba(51, 255, 102, 0.35);
  --ui-rojo: #FF3B30;
  --ui-panel-bg: rgba(0, 0, 0, 0.85);
  /* glow doble pasada: núcleo + halo (conGlow de theme.ts, rebajado a petición de David).
     El título usa la variante fuerte; los cuadros de texto la suave. */
  --ui-glow: 0 0 2px rgba(51, 255, 102, 0.35), 0 0 6px rgba(51, 255, 102, 0.15);
  --ui-glow-titulo: 0 0 3px rgba(51, 255, 102, 0.5), 0 0 8px rgba(51, 255, 102, 0.22);
}

/* === Post FX de la UI (aberración SVG + grano soft-light) === */
.ui-fx {
  filter: url(#ui-aberracion);
}

.ui-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-repeat: repeat;
  background-size: calc(64px * 4); /* GRANO_TILE × GRANO_ESCALA */
  image-rendering: pixelated;
  mix-blend-mode: soft-light;
  opacity: 0.06; /* = GRANO_OPACIDAD (rebajado a petición de David) */
}

/* === Panel consola (marco 3px + chip Silkscreen) === */
.ui-panel {
  background: var(--ui-panel-bg);
  border: 1px solid var(--ui-principal);
}

.ui-chip {
  position: absolute;
  top: -1px;
  left: 12px;
  transform: translateY(-50%);
  /* Por encima de hermanos posicionados posteriores (la barra del selector
     pintaba su fondo encima del chip y tapaba media palabra) */
  z-index: 1;
  background: #000;
  padding: 2px 8px;
  font-family: 'Silkscreen', monospace;
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
  user-select: none;
}

.ui-chip:empty {
  display: none;
}

/* === Texto stdout (cursor de bloque + cursiva sintética) === */
.stdout-line {
  white-space: pre-wrap;
}

.stdout-cursiva {
  display: inline-block;
  /* skew -0.22 de la consola + ensanche de la letra de serie */
  transform: skewX(-12.4deg) scaleX(var(--ui-ensanche));
  transform-origin: left center;
}

/* El título está centrado por flex: que crezca simétrico, no hacia la derecha */
#title-line .stdout-cursiva {
  transform-origin: center center;
}

.stdout-cursor {
  color: var(--ui-principal);
}

.stdout-cursor.blink {
  animation: stdout-blink 1s steps(2, jump-none) infinite;
}

@keyframes stdout-blink {
  0% { opacity: 1; }
  100% { opacity: 0; }
}

/* === Ensanche sintético de la letra de serie (VT323) ===
   transform no afecta al layout: los elementos centrados crecen
   simétricos; los alineados a la izquierda usan origin left. El track
   del selector lo mueve JS con translateX — se escalan las opciones,
   nunca el track. La fila de color tiene bordes a todo el ancho — se
   escalan sus spans, no la fila. Silkscreen (chips, HUD, hints) no se
   toca: esa ya es ancha. */
#title-hint,
.selector-option,
#hotspot-prompt-message,
#blocked-text,
#pointer-lock-message span,
#mode-row,
#cs-name-row,
#cs-tag,
#cs-stats,
#cs-color-row > span {
  transform: scaleX(var(--ui-ensanche));
}

.dialogue-option {
  transform: scaleX(var(--ui-ensanche));
  transform-origin: left center;
}

/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  overflow: hidden;
  background: #000;
  cursor: none;
  font-family: 'VT323', monospace;
  color: #fff;
  width: 100vw;
  height: 100vh;
}

/* === Canvas === */
canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100vw;
  height: 100vh;
}

/* === UI Overlay === */
#ui-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* === Screen (hidden by default, flex when .active) === */
.screen {
  display: none;
}

.screen.active {
  display: flex;
}

/* === Mode Select (jugar y grabar / solo jugar, antes del título) === */
#mode-select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 28px;
  background: #000;
  pointer-events: auto;
  z-index: 50;
  color: var(--ui-principal);
}

#mode-line {
  font-family: 'VT323', monospace;
  font-size: 34px;
  letter-spacing: 1px;
  text-shadow: var(--ui-glow);
  user-select: none;
  min-height: 36px;
}

#mode-row {
  font-size: 41px;
  letter-spacing: 2px;
  text-shadow: var(--ui-glow);
  padding: 0 10px;
  user-select: none;
}

#mode-hint {
  font-family: 'Silkscreen', monospace;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ui-tenue);
  user-select: none;
}

/* === Title Screen === */
#title-screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 48px;
  background: #000;
  pointer-events: auto;
  z-index: 50;
}

#title-line {
  font-family: 'VT323', monospace;
  font-size: 72px;
  color: var(--ui-principal);
  text-shadow: var(--ui-glow-titulo);
  user-select: none;
}

#title-hint {
  font-family: 'VT323', monospace;
  font-size: 26px;
  letter-spacing: 2px;
  color: var(--ui-tenue);
  user-select: none;
  opacity: 0;
}

#title-hint.visible {
  animation: hint-pulse 2s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 1; }
}

/* === Selector UI === */
#selector-ui {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  justify-content: center;
  align-items: flex-end;
  padding-bottom: 64px;
  z-index: 20;
}

#selector-wrap {
  position: relative;
}

/* Fixed-width viewport. Its internal track slides horizontally to cycle
   options. Overflow hidden clips the copies on either side of center. */
#selector-bar {
  position: relative;
  width: 720px;
  height: 52px;
  background: var(--ui-panel-bg);
  border: 1px solid var(--ui-principal);
  overflow: hidden;
  pointer-events: auto;
}

/* The track holds 3 copies of the options so the carousel can wrap
   seamlessly. JS moves it with translateX(). */
#selector-track {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 64px;
  padding: 0 40px;
  will-change: transform;
}

.selector-option {
  flex: 0 0 auto;
  font-family: 'VT323', monospace;
  font-size: 22px;
  color: var(--ui-tenue);
  letter-spacing: 2px;
  user-select: none;
  white-space: nowrap;
  padding: 3px 10px;
  transition: color 0.2s;
}

/* Seleccionada: bloque cian relleno, letras invertidas en negro (ref David) */
.selector-option.selected {
  color: #000;
  background: var(--ui-principal);
  box-shadow: var(--ui-glow);
}

/* Bloqueada al intentar elegirla: sacudida a saltos + bordes rojos + fondo
   gris. El borde va en box-shadow para no mover el layout (el centrado del
   track se mide con offsetLeft). Los keyframes repiten el scaleX del
   ensanche porque el transform de la animación lo sustituiría. */
.selector-option.sel-error {
  color: var(--ui-rojo);
  background: #4a4a4a;
  box-shadow: 0 0 0 2px var(--ui-rojo), 0 0 8px rgba(255, 59, 48, 0.6);
  transition: none;
  animation: selector-shake 0.42s steps(1, jump-end);
}

@keyframes selector-shake {
  0%     { transform: translateX(-6px) scaleX(var(--ui-ensanche)); }
  16.6%  { transform: translateX(6px)  scaleX(var(--ui-ensanche)); }
  33.3%  { transform: translateX(-5px) scaleX(var(--ui-ensanche)); }
  50%    { transform: translateX(5px)  scaleX(var(--ui-ensanche)); }
  66.6%  { transform: translateX(-3px) scaleX(var(--ui-ensanche)); }
  83.3%  { transform: translateX(3px)  scaleX(var(--ui-ensanche)); }
  100%   { transform: translateX(0)    scaleX(var(--ui-ensanche)); }
}

/* === Dialogue UI === */
#dialogue-ui {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 20;
}

#dialogue-ui.active {
  display: block;
}

/* NPC speech — floating text without a box, higher on the screen,
   shown letter by letter. Stays visible while the player chooses. */
#dialogue-npc {
  position: absolute;
  bottom: 260px;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  max-width: 640px;
  display: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 18px 20px 14px;
  pointer-events: none;
}

#dialogue-npc-history {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#dialogue-npc-history .stdout-line {
  color: var(--ui-tenue);
  text-shadow: none;
  /* Línea recién empujada al historial: sube con un fade breve.
     Solo opacity — .stdout-cursiva ya usa transform (skewX) en el mismo
     elemento, y animar transform aquí pisaría el skew durante los 0.25s. */
  animation: history-rise 0.25s ease-out;
}

@keyframes history-rise {
  from { opacity: 0; }
  to { opacity: 1; }
}

#dialogue-npc-text,
#dialogue-npc-history {
  font-family: 'VT323', monospace;
  font-size: 29px;
  line-height: 1.3;
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
  white-space: pre-wrap;
  user-select: none;
  /* ≈ 1/--ui-ensanche: las líneas se envuelven un poco antes para que el
     ensanche visual (transform, no afecta al layout) no cruce el marco */
  max-width: 89%;
}

/* Player box — lower, boxed, contains options + hint */
#dialogue-player {
  position: absolute;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  width: 70%;
  max-width: 640px;
  display: none;
  flex-direction: column;
  gap: 10px;
  padding: 20px 24px;
  pointer-events: auto;
}

#dialogue-options {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.dialogue-option {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  padding: 4px 8px;
  font-family: 'VT323', monospace;
  font-size: 24px;
  color: var(--ui-tenue);
  user-select: none;
  transition: color 0.15s;
}

.dialogue-option.selected {
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
}

.dialogue-option-arrow {
  visibility: hidden;
  color: var(--ui-principal);
  font-size: 24px;
  width: 14px;
  text-align: center;
}

.dialogue-option.selected .dialogue-option-arrow {
  visibility: visible;
}

#dialogue-hint {
  display: none;
  font-family: 'Silkscreen', monospace;
  font-size: 12px;
  color: var(--ui-tenue);
  text-align: center;
  padding-top: 10px;
  letter-spacing: 1px;
  user-select: none;
}

#dialogue-hint.visible {
  display: block;
}

/* === Hotspot Prompt === */
#hotspot-prompt {
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--ui-panel-bg);
  border: 1px solid var(--ui-principal);
  z-index: 15;
}

#hotspot-prompt-message {
  font-family: 'VT323', monospace;
  font-size: 24px;
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
  letter-spacing: 1px;
  user-select: none;
  text-align: center;
}

#hotspot-prompt-action {
  font-family: 'Silkscreen', monospace;
  font-size: 12px;
  color: var(--ui-tenue);
  letter-spacing: 2px;
  user-select: none;
  border: 1px solid var(--ui-tenue);
  padding: 4px 14px;
  text-align: center;
}

/* === Blocked Message ===
   Cuadro negro opaco con borde rojo. El padding lateral es generoso porque
   el texto lleva el ensanche (transform) y sobresale un 6% por cada lado
   respecto a su ancho de layout. */
#blocked-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  justify-content: center;
  align-items: center;
  padding: 14px 48px;
  background: #000;
  border: 2px solid var(--ui-rojo);
  z-index: 15;
}

#blocked-text {
  font-family: 'VT323', monospace;
  font-size: 26px;
  line-height: 1.15;
  color: var(--ui-rojo);
  text-shadow: 0 0 8px rgba(255, 59, 48, 0.8);
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  max-width: 620px;
  user-select: none;
}

/* === Voto de las demos (pantalla consola, como la de modo) === */
#demo-vote {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 26px;
  padding: 24px;
  background: #000;
  pointer-events: auto;
  z-index: 50;
  color: var(--ui-principal);
}

#vote-line,
#vote-result {
  font-family: 'VT323', monospace;
  font-size: 34px;
  letter-spacing: 1px;
  text-shadow: var(--ui-glow);
  user-select: none;
  min-height: 36px;
  text-align: center;
}

#vote-list {
  display: none;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}

.vote-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  font-family: 'VT323', monospace;
  font-size: 36px;
  color: var(--ui-tenue);
  user-select: none;
  transition: color 0.15s;
}

.vote-row.selected {
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
}

.vote-arrow {
  visibility: hidden;
  width: 18px;
  text-align: center;
}

.vote-row.selected .vote-arrow {
  visibility: visible;
}

#vote-hint {
  font-family: 'Silkscreen', monospace;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ui-tenue);
  user-select: none;
  min-height: 16px;
  text-align: center;
}

/* === Game over (la ruina del prólogo) === */
#game-over {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  justify-content: center;
  align-items: center;
  background: #000;
  z-index: 60;
  pointer-events: auto;
}

#game-over span {
  font-family: 'Silkscreen', monospace;
  font-size: 24px;
  letter-spacing: 4px;
  color: var(--ui-rojo);
  text-shadow: 0 0 8px rgba(255, 59, 48, 0.6);
  user-select: none;
}

/* === Error Texts (mirror glitch, Escena 1) === */
#error-texts {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 18;
}

.error-text {
  position: absolute;
  font-family: 'VT323', monospace;
  font-size: 19px;
  color: var(--ui-rojo);
  text-shadow: 0 0 8px #ff0000, 0 0 16px #ff000088;
  letter-spacing: 2px;
  user-select: none;
  opacity: 0;
  transition: opacity 0.4s ease-in-out;
}

.error-text.visible {
  opacity: 1;
}

/* === Pointer Lock Message === */
#pointer-lock-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  justify-content: center;
  align-items: center;
  z-index: 25;
}

#pointer-lock-message span {
  font-family: 'VT323', monospace;
  font-size: 19px;
  color: var(--ui-tenue);
  letter-spacing: 3px;
  user-select: none;
  animation: pulse-lock 2s ease-in-out infinite;
}

@keyframes pulse-lock {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* === Fade Overlay === */
#fade-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  opacity: 0;
  z-index: 100;
  pointer-events: none;
  transition: opacity 0.5s ease-in-out;
}

#fade-overlay.active {
  opacity: 1;
}

/* rec-blink: parpadeo del REC del HUD del modo foto */
@keyframes rec-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

/* === Character Select (SYS.DAVS // SELECCIÓN DE SUJETO) === */
#character-select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #000;
  /* Captura el ratón: sin esto los clicks atraviesan el overlay hasta el
     canvas del juego y activan pointer lock en plena selección */
  pointer-events: auto;
  align-items: center;
  justify-content: center;
  padding: 24px 32px;
  color: var(--ui-principal);
}

/* Marco 3:2 centrado (proporción del encuadre del videoclip): el
   contenido nunca toca los bordes de la ventana */
#cs-marco {
  display: flex;
  flex-direction: column;
  align-items: center;
  aspect-ratio: 3 / 2;
  height: 100%;
  max-width: 100%;
}

#cs-header {
  align-self: flex-start;
  width: 100%;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ui-tenue);
  font-family: 'Silkscreen', monospace;
  font-size: 17px;
  letter-spacing: 1px;
  text-shadow: var(--ui-glow);
  min-height: 26px;
}

#cs-centro {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 0;
}

#cs-preview-frame {
  position: relative;
  border: 1px solid var(--ui-tenue);
  background: #000;
  line-height: 0;
}

/* Capa ASCII sobre el render (solo bloqueados) — cubre el canvas GL */
#cs-canvas-ascii {
  display: none;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* X de prohibido gigante tapando la figura */
#cs-preview-x {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  font-size: calc(min(320px, 38vh) * 0.45);
  line-height: 1;
  color: var(--ui-rojo);
  opacity: 0.9;
  user-select: none;
}

#cs-preview-frame.cs-no-disponible #cs-canvas-ascii {
  display: block;
}

#cs-preview-frame.cs-no-disponible #cs-preview-x {
  display: flex;
}

/* Anula el canvas global (100vw/100vh). Render interno 96x128,
   escalado nearest a tamaño de demo-disc. */
#cs-canvas {
  height: min(320px, 38vh);
  aspect-ratio: 3 / 4;
  width: auto;
}

.cs-fila {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 10px;
}

.cs-fila .cs-arrow {
  visibility: hidden;
  text-shadow: var(--ui-glow);
}

.cs-fila.cs-foco .cs-arrow {
  visibility: visible;
}

#cs-name-row {
  font-size: 41px;
  letter-spacing: 2px;
  text-shadow: var(--ui-glow);
  padding: 0 10px;
}

#cs-tag {
  font-size: 23px;
  min-height: 26px;
  text-shadow: var(--ui-glow);
}

/* Sin cursor de bloque en esta línea: el texto de bloqueo sale de golpe
   y el █ ahí era ruido (petición de David) */
#cs-tag .stdout-cursor {
  display: none;
}

/* Línea de bloqueo/escalada en rojo (la etiqueta de la disponible queda
   en el color principal) — cursor del typer incluido */
#cs-tag.cs-tag-bloqueado,
#cs-tag.cs-tag-bloqueado .stdout-cursor {
  color: var(--ui-rojo);
  text-shadow: none;
}

#cs-tag.cs-error {
  animation: cs-error-flash 0.14s steps(2, jump-none) 3;
}

/* Parpadeo por opacidad: el texto bloqueado ya es rojo de base */
@keyframes cs-error-flash {
  0% { opacity: 1; }
  100% { opacity: 0.25; }
}

#cs-stats {
  font-size: 25px;
  line-height: 1.5;
  min-height: 64px;
  text-align: center;
  white-space: pre-wrap;
  text-shadow: var(--ui-glow);
}

#cs-stats.cs-bloqueado {
  color: var(--ui-tenue);
  text-shadow: none;
}

#cs-preview-frame.cs-shake {
  animation: cs-jitter 0.15s steps(2, jump-none) 2;
}

@keyframes cs-jitter {
  0% { transform: translate(2px, 0); }
  50% { transform: translate(-2px, 1px); }
  100% { transform: translate(0, -1px); }
}

#character-select.cs-confirmado #cs-name-row {
  animation: cs-confirm-flash 0.25s steps(2, jump-none) 1;
}

@keyframes cs-confirm-flash {
  0% { background: var(--ui-principal); color: #000; text-shadow: none; }
  100% { background: transparent; }
}

#cs-color-row {
  width: 100%;
  margin-top: auto;
  padding: 8px 0;
  border-top: 1px solid var(--ui-tenue);
  border-bottom: 1px solid var(--ui-tenue);
  font-size: 26px;
}

#cs-hint {
  margin-top: 10px;
  font-family: 'Silkscreen', monospace;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--ui-tenue);
}

/* === Modo Foto (dev, ?photo=1 + tecla O) === */
#photo-hud {
  position: absolute;
  left: 16px;
  bottom: 16px;
  display: none;
  padding: 16px 18px 12px;
  z-index: 30;
  pointer-events: none;
}

#photo-hud.active {
  display: block;
}

#photo-scene {
  font-family: 'Silkscreen', monospace;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--ui-tenue);
  user-select: none;
}

.photo-row {
  display: flex;
  gap: 12px;
  font-family: 'VT323', monospace;
  font-size: 17px;
  line-height: 1.4;
  transform: scaleX(var(--ui-ensanche));
  transform-origin: left center;
  user-select: none;
}

.photo-k {
  min-width: 118px;
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
  white-space: nowrap;
}

.photo-d {
  color: var(--ui-tenue);
}

#photo-status {
  margin-top: 8px;
  font-family: 'Silkscreen', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--ui-principal);
  user-select: none;
}

#photo-status:empty {
  margin-top: 0;
}

#photo-status .photo-st-rec {
  color: #e64545;
  animation: rec-blink 1s ease-in-out infinite;
}

#photo-status .photo-sep {
  color: var(--ui-tenue);
}


/* === Controles táctiles (html.touch — js/systems/touch-controls.js) ===
   Joystick redondo al andar; al interactuar, el bloque de botones del
   linktree de davs (intro grande + dos flechas, .btn de globals.css).
   Todo scoped a html.touch (+ portrait/landscape): desktop no cambia. */
html.touch body,
html.touch canvas {
  height: 100dvh;
}

html.touch #dialogue-hint,
html.touch #pointer-lock-message {
  display: none !important;
}

/* El cuadro del prompt es un botón: "pulsar" debajo del texto */
html.touch #hotspot-prompt {
  pointer-events: auto;
}

/* Flechas < > siempre visibles en la selección de sujeto: son las áreas de toque */
html.touch .cs-fila .cs-arrow {
  visibility: visible;
}

/* La selección de sujeto no tiene z-index: sin esto el stick (z 12) se
   pintaba encima de la pantalla en móvil */
html.touch #character-select {
  z-index: 50;
}

#touch-layer {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: auto;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* --- Joystick (redondo: base y knob) --- */
#touch-stick {
  position: absolute;
  display: none;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid var(--ui-tenue);
}

#touch-stick.visible {
  display: block;
}

/* Vertical: centrado abajo. Horizontal: abajo a la izquierda, fijo. */
html.portrait #touch-stick {
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  margin-left: -62px;
}

html.landscape #touch-stick {
  left: calc(28px + env(safe-area-inset-left));
  bottom: calc(24px + env(safe-area-inset-bottom));
}

#touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: var(--ui-principal);
  box-shadow: var(--ui-glow);
}

/* --- Bloque de botones (linktree: #controles / .btn) --- */
#touch-cluster {
  position: absolute;
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  height: 128px;
}

#touch-cluster.visible {
  display: grid;
}

html.portrait #touch-cluster {
  left: 16px;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
}

html.landscape #touch-cluster {
  right: calc(20px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 300px;
  height: 110px;
}

#touch-arrows {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 12px;
}

/* Selector: carrusel horizontal → ◀ ▶ uno al lado del otro */
#touch-arrows.h {
  grid-template-rows: none;
  grid-template-columns: 1fr 1fr;
}

.touch-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 1px solid var(--ui-principal);
  background: rgba(0, 0, 0, 0.6);
  color: var(--ui-principal);
  font-family: 'Silkscreen', monospace;
  font-size: 15px;
  letter-spacing: 1px;
  text-shadow: var(--ui-glow);
}

.touch-btn.pressed {
  background: var(--ui-principal);
  color: #000;
  text-shadow: none;
}

.touch-btn.inert {
  opacity: 0.3;
}

#touch-enter-label {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#touch-enter-label:empty {
  display: none;
}

#touch-cancel {
  position: absolute;
  display: none;
  right: calc(16px + env(safe-area-inset-right));
  top: calc(16px + env(safe-area-inset-top));
  width: 44px;
  height: 44px;
  line-height: 40px;
  text-align: center;
  background: var(--ui-panel-bg);
  border: 2px solid var(--ui-rojo);
  font-family: 'Silkscreen', monospace;
  font-size: 16px;
  color: var(--ui-rojo);
}

#touch-cancel.visible {
  display: block;
}

#touch-cancel.pressed {
  background: var(--ui-rojo);
  color: #000;
}

/* --- Layout vertical: la UI se sube por encima del bloque de botones --- */
html.touch.portrait #selector-ui {
  padding-bottom: calc(168px + env(safe-area-inset-bottom));
}

html.touch.portrait #selector-bar {
  width: calc(100vw - 24px);
  height: 46px;
}

html.touch.portrait .selector-option {
  font-size: 17px;
  letter-spacing: 1px;
  padding: 2px 8px;
}

html.touch.portrait #selector-track {
  gap: 40px;
  padding: 0 24px;
}

html.touch.portrait #dialogue-player {
  bottom: calc(168px + env(safe-area-inset-bottom));
  width: 92%;
  padding: 14px 16px;
}

html.touch.portrait #dialogue-npc {
  bottom: auto;
  top: 8%;
  width: 92%;
}

html.touch.portrait #dialogue-npc-text,
html.touch.portrait #dialogue-npc-history {
  font-size: 23px;
}

html.touch.portrait .dialogue-option {
  font-size: 21px;
}

html.touch.portrait #hotspot-prompt {
  top: 40%;
  max-width: 88vw;
}

html.touch.portrait #title-line {
  font-size: 56px;
}

/* Voto de las demos: bajo la capa táctil (z 12) para que el bloque de
   botones del linktree se pinte encima; el hint de teclado sobra */
html.touch #demo-vote {
  z-index: 11;
}

html.touch #vote-hint {
  display: none;
}

html.touch.portrait #demo-vote {
  padding-bottom: calc(170px + env(safe-area-inset-bottom));
}

html.touch.landscape #demo-vote {
  padding-bottom: calc(130px + env(safe-area-inset-bottom));
}

html.touch.portrait #vote-line,
html.touch.portrait #vote-result {
  font-size: 26px;
}

html.touch.portrait .vote-row {
  font-size: 30px;
}

html.touch.portrait #blocked-text {
  font-size: 22px;
  max-width: 80vw;
}

html.touch.portrait #cs-marco {
  aspect-ratio: auto;
  width: 100%;
}

/* Selección de sujeto en vertical: la fila de color no cabe en una línea */
html.touch.portrait #cs-color-row {
  flex-wrap: wrap;
  row-gap: 4px;
  font-size: 22px;
}

html.touch.portrait #cs-name-row {
  font-size: 34px;
}

/* --- Layout horizontal: paneles a la izquierda, bloque de botones a la
   derecha, joystick abajo-izquierda --- */
html.touch.landscape #selector-ui {
  justify-content: flex-start;
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-bottom: 20px;
}

html.touch.landscape #selector-bar {
  width: calc(100vw - 352px - env(safe-area-inset-left) - env(safe-area-inset-right));
  height: 46px;
}

html.touch.landscape .selector-option {
  font-size: 19px;
  letter-spacing: 1px;
}

html.touch.landscape #dialogue-npc,
html.touch.landscape #dialogue-player {
  left: calc(12px + env(safe-area-inset-left));
  transform: none;
  width: calc(100vw - 352px - env(safe-area-inset-left) - env(safe-area-inset-right));
  max-width: none;
}

html.touch.landscape #dialogue-npc {
  bottom: 150px;
  padding: 12px 16px 10px;
}

html.touch.landscape #dialogue-npc-text,
html.touch.landscape #dialogue-npc-history {
  font-size: 22px;
}

html.touch.landscape #dialogue-player {
  bottom: 16px;
  padding: 12px 18px;
}

html.touch.landscape .dialogue-option {
  font-size: 19px;
  padding: 2px 8px;
}

html.touch.landscape #hotspot-prompt {
  top: 50%;
  left: calc(50% - 160px);
  max-width: calc(100vw - 360px);
}

/* Selección de sujeto en horizontal (375px de alto): preview a la izquierda
   y textos a la derecha, letra menor — en columna no cabía y se montaba */
html.touch.landscape #character-select {
  padding: 12px 24px;
}

html.touch.landscape #cs-marco {
  aspect-ratio: auto;
  width: 100%;
}

html.touch.landscape #cs-header {
  font-size: 13px;
  padding-bottom: 4px;
  min-height: 0;
}

html.touch.landscape #cs-centro {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto auto;
  column-gap: 24px;
  row-gap: 4px;
  align-items: center;
  justify-items: start;
}

html.touch.landscape #cs-preview-frame {
  grid-row: 1 / 4;
}

html.touch.landscape #cs-canvas {
  height: min(200px, 44vh);
}

html.touch.landscape #cs-preview-x {
  font-size: calc(min(200px, 44vh) * 0.45);
}

html.touch.landscape #cs-name-row {
  font-size: 28px;
  padding: 0;
}

html.touch.landscape #cs-tag {
  font-size: 18px;
  min-height: 20px;
}

html.touch.landscape #cs-stats {
  font-size: 18px;
  line-height: 1.35;
  min-height: 0;
  text-align: left;
}

html.touch.landscape #cs-color-row {
  font-size: 19px;
  padding: 4px 0;
}

html.touch.landscape #cs-hint {
  margin-top: 4px;
  font-size: 11px;
}

/* --- Cartel de fin del viaje (móvil): a los ~75 s en la nave --- */
#touch-end {
  position: absolute;
  display: none;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  background: var(--ui-panel-bg);
  border: 1px solid var(--ui-principal);
}

#touch-end.visible {
  display: flex;
}

#touch-end-msg {
  font-family: 'Silkscreen', monospace;
  font-size: 15px;
  letter-spacing: 1px;
  color: var(--ui-principal);
  text-shadow: var(--ui-glow);
  white-space: nowrap;
}

#touch-exit {
  width: 150px;
  height: 52px;
}
