@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&family=VT323&display=swap");

:root {
  --bg-dark: #111318;
  --bg-hud: rgba(20, 23, 31, 0.92);
  --border-hud: rgba(255, 255, 255, 0.12);
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;

  --bubble-bg: #00bfff;
  --bubble-text: #041036;
  --bubble-border: #05070a;

  --bubble-human-bg: #7bed9f;
  --bubble-human-text: #072b15;

  --bubble-error-bg: #ff8596;
  --bubble-error-text: #38040e;

  --accent-teal: #57b8ad;
  --accent-amber: #eba046;
  --accent-green: #2ed573;
  --accent-red: #ff4757;

  --focus-ring: 0 0 0 3px #ffffff, 0 0 0 6px #00bfff;
  --stage-scale: 1;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  background-image: radial-gradient(circle at 50% 45%, #232834 0%, #0d0f14 100%);
  color: var(--text-main);
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

/* ==========================================================================
   BARRA SUPERIOR (HUD)
   ========================================================================== */
#app-hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 54px;
  background: var(--bg-hud);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-hud);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  z-index: 30;
  gap: 12px;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-right: 6px;
}

.brand-series {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--accent-teal);
  text-transform: uppercase;
}

.brand-chapter {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
}

.hud-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-muted);
  text-transform: uppercase;
}

.hud-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6b7280;
}

.hud-badge.is-live {
  background: rgba(46, 213, 115, 0.16);
  color: #7bed9f;
  border: 1px solid rgba(46, 213, 115, 0.35);
}

.hud-badge.is-live::before {
  background: var(--accent-green);
  box-shadow: 0 0 8px var(--accent-green);
  animation: pulseDot 1.4s infinite ease-in-out;
}

.hud-timer {
  font-family: "VT323", monospace;
  font-size: 22px;
  color: var(--accent-amber);
  background: rgba(0, 0, 0, 0.4);
  padding: 2px 10px;
  border-radius: 6px;
  border: 1px solid rgba(235, 160, 70, 0.25);
  min-width: 58px;
  text-align: center;
}

.hud-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

.hud-btn {
  appearance: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease, border-color 0.15s ease, opacity 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.hud-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.28);
}

.hud-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.hud-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.hud-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.hud-btn.is-active {
  background: rgba(87, 184, 173, 0.22);
  border-color: var(--accent-teal);
  color: #a8ece4;
}

.hud-btn.is-muted {
  background: rgba(255, 71, 87, 0.2);
  border-color: var(--accent-red);
  color: #ff9aa2;
}

.hud-btn.is-danger {
  background: rgba(255, 71, 87, 0.18);
  border-color: rgba(255, 71, 87, 0.45);
  color: #ffb8c0;
}

.hud-btn.is-danger:hover:not(:disabled) {
  background: rgba(255, 71, 87, 0.32);
}

/* ==========================================================================
   ESCENARIO PRINCIPAL A PANTALLA COMPLETA (AUTO-ESCALADO)
   ========================================================================== */
#app-viewport {
  position: fixed;
  top: 54px;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#stage-scale-wrapper {
  width: 940px;
  height: 810px;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: scale(var(--stage-scale, 1));
  transform-origin: center center;
  flex-shrink: 0;
}

#talk-to-a-human-game {
  background-image: url("../images/bg-vintage-phone-940.png");
  background-repeat: no-repeat;
  background-position: top left;
  background-size: 940px 810px;
  width: 940px;
  height: 810px;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  align-items: flex-start;
  gap: 68px;
  padding: 220px 52px 40px 90px;
  border-radius: 18px;
}

/* ==========================================================================
   PANEL DEL TELÉFONO (LCD + NUMPAD)
   Coordenadas exactas sincronizadas con bg-vintage-phone-940.png
   ========================================================================== */
#tth-phone-panel {
  display: flex;
  flex-direction: column;
  gap: 40px;
  width: 360px;
  flex-shrink: 0;
  position: relative;
}

.lcd-container {
  position: relative;
  width: 360px;
  height: 120px;
}

#tth-lcd-hint {
  position: absolute;
  top: 6px;
  left: 14px;
  font-family: "VT323", monospace;
  font-size: 18px;
  letter-spacing: 0.06em;
  color: rgba(0, 0, 0, 0.72);
  pointer-events: none;
  z-index: 2;
}

#tth-lcd-display {
  width: 100%;
  height: 120px;
  background-color: transparent;
  color: #120d06;
  font-family: "VT323", monospace;
  font-size: 110px;
  line-height: 1;
  padding: 8px 14px 4px;
  text-align: right;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  border: none;
  border-radius: 10px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

#tth-lcd-display.is-password-mode {
  letter-spacing: 0.08em;
  justify-content: center;
  text-align: center;
}

#image-numpad {
  position: relative;
  width: 360px;
  height: 360px;
  overflow: hidden;
  touch-action: none;
}

.numpad-hotspot {
  position: absolute;
  cursor: pointer;
  border: none;
  background-color: transparent;
  border-radius: 8px;
  background-image: url("../images/ui-numpad-360.png");
  background-repeat: no-repeat;
  padding: 0;
  touch-action: none;
}

.numpad-hotspot:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  z-index: 3;
}

/* ==========================================================================
   BOCADILLO DE DIÁLOGO (CONTESTADOR / HUMANO)
   ========================================================================== */
#tth-speech-bubble {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  width: 370px;
  max-width: 370px;
  min-height: 130px;
  max-height: 520px;
  padding: 18px 22px 20px;
  background-color: var(--bubble-bg);
  color: var(--bubble-text);
  border: 4px solid var(--bubble-border);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.55);
  border-radius: 24px;
  position: relative;
  z-index: 5;
  transition: background-color 0.25s ease, color 0.25s ease;
}

#tth-speech-bubble.is-human-agent {
  background-color: var(--bubble-human-bg);
  color: var(--bubble-human-text);
}

#tth-speech-bubble.is-error-node {
  background-color: var(--bubble-error-bg);
  color: var(--bubble-error-text);
}

#tth-speech-bubble.subtitles-hidden {
  opacity: 0;
  pointer-events: none;
}

.speech-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
  margin-bottom: 10px;
  border-bottom: 2px solid rgba(0, 0, 0, 0.14);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#tth-speech-text {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-y: auto;
  text-align: left;
  user-select: text;
  padding-right: 4px;
}

/* Indicador visual de onda de voz activa */
.speaking-wave {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 14px;
  opacity: 0.25;
}

.speaking-wave span {
  width: 3px;
  height: 4px;
  background: currentColor;
  border-radius: 2px;
}

.speaking-wave.is-speaking {
  opacity: 1;
}

.speaking-wave.is-speaking span:nth-child(1) {
  animation: waveBar 0.6s infinite ease-in-out 0s;
}
.speaking-wave.is-speaking span:nth-child(2) {
  animation: waveBar 0.6s infinite ease-in-out 0.15s;
}
.speaking-wave.is-speaking span:nth-child(3) {
  animation: waveBar 0.6s infinite ease-in-out 0.3s;
}
.speaking-wave.is-speaking span:nth-child(4) {
  animation: waveBar 0.6s infinite ease-in-out 0.1s;
}

/* ==========================================================================
   PANTALLA DE INICIO / DESCOLGAR (OVERLAY)
   ========================================================================== */
#start-overlay {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(
      to bottom,
      rgba(12, 15, 20, 0.35) 0%,
      rgba(12, 15, 20, 0.72) 100%
    ),
    url("../images/bg-telephone-overlay-940.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  z-index: 15;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 24px;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

.overlay-header {
  text-align: center;
  background: rgba(15, 18, 25, 0.85);
  backdrop-filter: blur(8px);
  padding: 16px 28px;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.overlay-header h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.03em;
  color: #ffffff;
  margin-bottom: 4px;
}

.overlay-header p {
  font-size: 14px;
  color: #cbd5e1;
}

#start-game-button {
  width: 230px;
  height: 230px;
  cursor: pointer;
  border: none;
  background-color: transparent;
  background-image: url("../images/icon-call-green-phone-420.png");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  transition: transform 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
  animation: pumpEffect 2s infinite ease-in-out;
  border-radius: 50%;
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.65));
}

#start-game-button:hover:not(:disabled),
#start-game-button:focus-visible {
  outline: none;
  animation-play-state: paused;
  transform: scale(1.08);
  filter: drop-shadow(0 0 20px rgba(46, 213, 115, 0.75));
}

#start-game-button:active:not(:disabled) {
  transform: scale(1.02);
}

#start-game-button:disabled {
  cursor: wait;
  opacity: 0.55;
  animation: none;
}

#loading-indicator {
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
  background: rgba(15, 18, 25, 0.85);
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* ==========================================================================
   MENSAJES DEL SISTEMA / FEEDBACK INFERIOR
   ========================================================================== */
#tth-system-messages {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: 92%;
  max-width: 820px;
  text-align: center;
  z-index: 20;
  pointer-events: none;
}

.sys-msg {
  display: inline-block;
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  background: rgba(15, 18, 25, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.sys-msg.info {
  color: #e2e8f0;
}

.sys-msg.error {
  color: #fecdd3;
  border-color: rgba(255, 71, 87, 0.5);
  background: rgba(68, 10, 20, 0.9);
}

.sys-msg.success {
  color: #bbf7d0;
  border-color: rgba(46, 213, 115, 0.5);
  background: rgba(8, 48, 24, 0.92);
}

/* ==========================================================================
   PANEL DE DESARROLLO / INSPECTOR DE NODOS (DEBUG DRAWER)
   ========================================================================== */
#debug-drawer {
  position: fixed;
  top: 64px;
  right: 14px;
  width: 330px;
  max-height: calc(100dvh - 80px);
  background: rgba(17, 20, 28, 0.96);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.65);
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-size: 13px;
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-weight: 700;
  color: var(--accent-teal);
}

.debug-body {
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.debug-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.debug-stat {
  background: rgba(255, 255, 255, 0.05);
  padding: 8px;
  border-radius: 8px;
  text-align: center;
}

.debug-stat small {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.debug-stat strong {
  font-family: "VT323", monospace;
  font-size: 20px;
  color: #ffffff;
}

.debug-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 7px;
  margin-bottom: 6px;
  cursor: pointer;
}

.debug-switch-row input {
  margin-right: 8px;
}

.debug-badge {
  font-size: 10px;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 4px;
}

.debug-badge.on {
  background: rgba(46, 213, 115, 0.2);
  color: #7bed9f;
}

.debug-badge.off {
  background: rgba(255, 71, 87, 0.2);
  color: #ff9aa2;
}

.debug-jump-row {
  display: flex;
  gap: 6px;
}

#debug-node-select {
  flex: 1;
  min-width: 0;
  background: #0d1017;
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
}

#debug-history-list {
  font-family: "VT323", monospace;
  font-size: 17px;
  color: var(--accent-amber);
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 10px;
  border-radius: 6px;
  word-break: break-word;
}

/* ==========================================================================
   UTILIDADES Y ANIMACIONES
   ========================================================================== */
.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@keyframes speechBubbleGrow {
  0% {
    opacity: 0;
    transform: scale(0.88) translateY(8px);
  }
  70% {
    opacity: 1;
    transform: scale(1.02) translateY(0);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

#tth-speech-bubble.popup-active {
  animation: speechBubbleGrow 0.38s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes pumpEffect {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.06);
  }
}

@keyframes pulseDot {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

@keyframes waveBar {
  0%,
  100% {
    height: 4px;
  }
  50% {
    height: 14px;
  }
}

@media (max-width: 780px) {
  .brand-chapter,
  .hud-count {
    display: none;
  }
  #app-hud {
    padding: 0 10px;
  }
  .hud-btn span.btn-label-desktop {
    display: none;
  }
}
