:root {
  --bg-dark: #09090b;
  --bg-card: rgba(20, 20, 25, 0.7);
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --text-primary: #f4f4f5;
  --text-secondary: #a1a1aa;
  --success: #22c55e;
  --warning: #eab308;
  --danger: #ef4444;
  --border: rgba(255, 255, 255, 0.08);
  --font-display: 'Orbitron', system-ui, sans-serif;
  --font-body: 'Outfit', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  height: 100dvh; /* Altura dinâmica do viewport para celulares */
}

/* Tela de Autenticação Segura (Overlay) */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 9, 11, 0.95);
  backdrop-filter: blur(20px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99999;
  padding: 20px;
  transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: rgba(20, 20, 25, 0.6);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 24px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5),
              0 0 40px rgba(139, 92, 246, 0.1);
  backdrop-filter: blur(16px);
  animation: cardFadeIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardFadeIn {
  0% {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

.login-logo h2 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--text-primary);
}

.login-logo h2 span {
  color: var(--accent);
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 28px;
  line-height: 1.5;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
  text-align: left;
}

.input-group label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent-hover);
}

.input-group input {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 14px;
  outline: none;
  transition: all 0.25s ease;
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.2);
  background: rgba(0, 0, 0, 0.5);
}

.login-error-msg {
  color: var(--danger);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 16px;
  display: none;
  animation: shake 0.3s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.login-btn {
  width: 100%;
  background: linear-gradient(135deg, var(--accent) 0%, #6d28d9 100%);
  border: none;
  border-radius: 14px;
  color: var(--text-primary);
  padding: 14px;
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.login-btn:hover {
  background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
  box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
}

.login-btn:active {
  transform: scale(0.98);
}

/* Header */
.app-header {
  height: 60px;
  background: linear-gradient(180deg, rgba(15, 15, 20, 0.8) 0%, rgba(9, 9, 11, 0) 100%);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo h1 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 1px;
}

.logo h1 span {
  color: var(--accent);
}

.pixel-art-icon {
  font-size: 20px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.04);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  transition: all 0.3s ease;
}

.indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--text-secondary);
}

.status-badge.connected .indicator-dot {
  background-color: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status-badge.connecting .indicator-dot {
  background-color: var(--warning);
  box-shadow: 0 0 8px var(--warning);
  animation: pulse 1.5s infinite;
}

.status-badge.disconnected .indicator-dot {
  background-color: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

/* Área do Jogo */
.game-wrapper {
  flex: 1;
  position: relative;
  background-color: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
  touch-action: none;
}

.vnc-container {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

/* Cursor Virtual Customizado */
.virtual-cursor {
  position: absolute;
  width: 24px;
  height: 24px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none'><path d='M4.5 3V19L9.4 14.1L13.7 22L16.3 20.6L12.1 12.8L18.5 12.8L4.5 3Z' fill='%238b5cf6' stroke='white' stroke-width='1.5' stroke-linejoin='miter'/></svg>");
  background-size: contain;
  background-repeat: no-repeat;
  pointer-events: none; /* não obstrui cliques */
  z-index: 9999;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

/* noVNC injeta canvas ou div dentro do container. Forçamos a caber de forma responsiva */
.vnc-container > div {
  width: 100% !important;
  height: 100% !important;
  display: flex;
  justify-content: center;
  align-items: center;
}

.vnc-container canvas {
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  touch-action: none;
}

/* Overlay de Carregamento */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(9, 9, 11, 0.9);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  z-index: 5;
  transition: opacity 0.5s ease;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(139, 92, 246, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-msg {
  font-family: var(--font-display);
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  text-align: center;
  padding: 0 20px;
}

/* Painel de Controles */
.control-panel {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: calc(36px + env(safe-area-inset-bottom)); /* Margem inferior aumentada para 36px para evitar sobreposição da barra virtual */
  z-index: 10;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-title {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  border-left: 2px solid var(--accent);
  padding-left: 6px;
}

/* Botões do Mouse */
.mouse-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ctrl-btn {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  padding: 12px 6px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.ctrl-btn:active {
  transform: scale(0.95);
}

.ctrl-btn.active {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0.05) 100%);
  border-color: var(--accent);
  color: var(--text-primary);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.2);
}

.btn-icon {
  font-size: 16px;
}

/* Atalhos de Teclado */
.keyboard-shortcuts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.key-btn {
  flex: 1;
  min-width: 60px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 10px;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
}

.key-btn:active {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(0.92);
}

.key-btn.special-key {
  background: rgba(139, 92, 246, 0.08);
  border-color: rgba(139, 92, 246, 0.3);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  font-family: var(--font-body);
  font-weight: 600;
}

/* Botões de Ação do Sistema */
.row-group {
  flex-direction: row;
  justify-content: space-between;
  gap: 8px;
}

.action-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  padding: 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.action-btn.active {
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.04);
}

.action-btn:active {
  transform: scale(0.96);
}

/* Input Invisível */
.invisible-input {
  position: absolute;
  top: -100px;
  left: -100px;
  width: 1px;
  height: 1px;
  opacity: 0;
  z-index: -999;
}

/* Animações */
@keyframes spin {
  to { transform: rotate(360deg); }
}

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

/* Responsividade de orientação */
@media (orientation: landscape) {
  body {
    flex-direction: row;
  }
  
  .app-header {
    width: 60px;
    height: 100%;
    flex-direction: column;
    padding: 16px 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
    justify-content: space-between;
  }
  
  .logo h1 {
    display: none; /* Oculta texto da logo para caber na barra vertical */
  }
  
  .status-badge {
    padding: 6px;
    border-radius: 50%;
  }
  
  .status-text {
    display: none;
  }
  
  .game-wrapper {
    flex: 2;
    height: 100%;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }
  
  .control-panel {
    flex: 1;
    max-width: 300px;
    height: 100%;
    border-top: none;
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding-bottom: 16px;
  }
}

/* Wrapper do Trackpad e do Scroll móvel lado a lado */
.trackpad-container-wrapper {
  display: flex;
  gap: 8px;
  width: 100%;
  height: 105px;
}

/* Área do Trackpad Customizada */
.trackpad-area {
  flex: 1;
  height: 100%;
  background: rgba(255, 255, 255, 0.01);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  touch-action: none; /* impede rolagem da tela ao arrastar */
  transition: all 0.3s ease;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
}

.trackpad-area:active {
  background: rgba(139, 92, 246, 0.02);
  border-color: rgba(139, 92, 246, 0.3);
}

/* Área do Scroll Virtual Móvel */
.trackpad-scroll-area {
  width: 50px;
  height: 100%;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  touch-action: none;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
  cursor: ns-resize;
  transition: all 0.3s ease;
}

.trackpad-scroll-area:active {
  background: rgba(139, 92, 246, 0.06);
  border-color: rgba(139, 92, 246, 0.35);
}

.scroll-track {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 8px 0;
  pointer-events: none;
}

.scroll-arrow {
  font-size: 8px;
  color: var(--text-secondary);
  opacity: 0.5;
}

.scroll-label {
  font-family: var(--font-display);
  font-size: 8px;
  font-weight: 800;
  color: var(--accent-hover);
  letter-spacing: 0.5px;
  writing-mode: vertical-lr;
  text-orientation: mixed;
  opacity: 0.8;
}

.trackpad-label {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--text-secondary);
  pointer-events: none;
  opacity: 0.6;
  z-index: 1;
  text-align: center;
  padding: 0 8px;
}

.trackpad-ripple {
  position: absolute;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(139, 92, 246, 0.3);
  box-shadow: 0 0 10px rgba(139, 92, 246, 0.5);
  transform: translate(-50%, -50%) scale(0);
  pointer-events: none;
  opacity: 0;
  transition: transform 0.08s ease-out, opacity 0.08s ease-out;
}

.trackpad-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 8px;
}

.click-btn {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.03) 0%, rgba(255, 255, 255, 0.01) 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  padding: 10px 8px; /* Reduzido de 16px para 10px para economizar altura vertical */
  font-family: var(--font-display);
  font-size: 12px; /* Reduzido de 13px para 12px */
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.click-btn:active,
.click-btn.active {
  transform: scale(0.95);
}

.click-btn.left-click:active,
.click-btn.left-click.active {
  background: rgba(139, 92, 246, 0.2);
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(139, 92, 246, 0.4);
}

.click-btn.right-click:active,
.click-btn.right-click.active {
  background: rgba(234, 179, 8, 0.15);
  border-color: var(--warning);
  box-shadow: 0 0 15px rgba(234, 179, 8, 0.3);
}

.game-wrapper canvas {
  transition: transform 0.20s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Barra de Ferramentas do Trackpad */
.trackpad-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
}

.toolbar-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  padding: 8px 6px;
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  transition: all 0.15s ease;
}

.toolbar-btn:active {
  background: var(--accent);
  border-color: var(--accent);
  transform: scale(0.95);
}

.zoom-controls {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 4px;
}

.zoom-btn {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 12px;
  padding: 6px 8px;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.zoom-btn:active {
  opacity: 0.5;
}

.zoom-val {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-hover);
  min-width: 48px;
  text-align: center;
}

/* Responsividade: Exibição inteligente dos painéis de controle */
@media (min-width: 769px) {
  #mobile-trackpad-panel {
    display: none !important;
  }
  #desktop-controls-group {
    display: flex !important;
  }
}

@media (max-width: 768px) {
  #mobile-trackpad-panel {
    display: flex !important;
  }
  #desktop-controls-group {
    display: none !important;
  }
}
