/* ============================================================
   TECLADO NA TELA (OSK) — frontend/public/js/osk.js
   Aparece em aparelhos SEM teclado físico E SEM teclado virtual
   próprio (handhelds Linux/aarch64 tipo R36S, quiosques, mini-PCs).
   Ver Configurações → Interface → "Teclado na tela".
   ============================================================ */

:root {
  /* Altura REAL do teclado aberto (medida e publicada pelo osk.js).
     O layout do app usa esse valor para SUBIR e não cobrir o campo. */
  --osk-h: 0px;
  /* Altura de cada tecla (acompanha a tela: 480p do R36S → teclas menores) */
  --osk-key-h: clamp(26px, 6.4vh, 40px);
}

/* ---------- Barra do teclado ---------- */
#osk {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 480; /* acima dos modais (200) e avisos (400) */
  display: none;
  flex-direction: column;
  gap: 5px;
  padding: 6px 6px 8px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.45);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#osk.osk-visible {
  display: flex;
  animation: jdSlideUp var(--anim-dur) var(--anim-ease);
}

html.no-motion #osk.osk-visible,
html.reduce-motion #osk.osk-visible {
  animation: none;
}

#osk .osk-rows {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

#osk .osk-row {
  display: flex;
  gap: 5px;
}

/* ---------- Teclas ---------- */
#osk .osk-key {
  flex: 1 1 0;
  min-width: 0;
  height: var(--osk-key-h);
  padding: 0 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-normal);
  font-family: inherit;
  font-size: calc(15px * var(--font-scale));
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
}

#osk .osk-key .mi {
  font-size: calc(19px * var(--ui-scale));
}

#osk .osk-key:hover {
  background: var(--bg-hover);
}

/* Tecla DESTACADA (navegação por D-pad/setas): é o "cursor" do teclado */
#osk .osk-key:focus {
  background: var(--blurple);
  color: #fff;
  outline: 2px solid #fff;
  outline-offset: -2px;
}

#osk .osk-key:active {
  background: var(--blurple-hover);
}

#osk .osk-key-act {
  background: var(--bg-soft);
}

#osk .osk-key-enter,
#osk .osk-key-back {
  background: var(--btn-secondary-bg);
}

/* Shift ativo */
#osk .osk-key-on {
  background: var(--blurple);
  color: #fff;
}

/* ---------- O layout do app sobe para o teclado não cobrir o campo ---------- */
html.osk-open #app {
  height: calc(100vh - var(--osk-h));
}

@supports (height: 100dvh) {
  html.osk-open #app {
    height: calc(100dvh - var(--osk-h));
  }
}

html.osk-open #login-screen,
html.osk-open .modal-backdrop {
  bottom: var(--osk-h);
}

/* ---------- Botão flutuante (abre/fecha o teclado) ---------- */
#osk-toggle {
  position: fixed;
  right: 12px;
  bottom: calc(var(--osk-h) + 12px);
  z-index: 479;
  width: calc(42px * var(--ui-scale));
  height: calc(42px * var(--ui-scale));
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
  border-radius: 50%;
  background: var(--bg-soft);
  color: var(--text-normal);
  cursor: pointer;
  opacity: 0.85;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  transition: opacity 0.15s, background 0.15s;
}

#osk-toggle:hover,
#osk-toggle:focus {
  opacity: 1;
  background: var(--bg-hover);
}

#osk-toggle .mi {
  font-size: calc(22px * var(--ui-scale));
}

#osk-toggle.hidden {
  display: none !important;
}

/* Telas baixas (640x480 do R36S): teclas mais compactas */
@media (max-height: 520px) {
  :root {
    --osk-key-h: clamp(24px, 6vh, 32px);
  }
  #osk .osk-key {
    font-size: calc(13px * var(--font-scale));
  }
}
