/**
 * =============================================================================
 * public/player/game-keyboard.css
 * Dedykowana klawiatura ekranowa dopasowana do stylu teleturnieju Party Quiz.
 * Stylistyka: Komiksowa Jackbox Party Indie (Grube obrysy, twarde cienie pop-art,
 * mięsiste klocki klawiszy, zero rozmytych neonów i laserów).
 * =============================================================================
 */

/* ── 0. TYMCZASOWE WYŁĄCZENIE DEDYKOWANEJ KLAWIATURY (WYMUSZENIE KLAWIATURY SYSTEMOWEJ) ── */
.game-virtual-keyboard,
#game-virtual-keyboard,
.gkb-floating-pill,
#gkb-floating-pill {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

#player-app-shell.keyboard-open .screen {
  padding-bottom: env(safe-area-inset-bottom, 16px) !important;
}

/* ── 1. GŁÓWNY KONTENER KLAWIATURY ─────────────────────────────────────────── */
.game-virtual-keyboard {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: #19102f;
  border-top: 3.5px solid #181824;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 0 #0e091b, 0 -12px 30px rgba(0, 0, 0, 0.65);
  padding: 6px 6px calc(8px + env(safe-area-inset-bottom, 0px)) 6px;
  gap: 4px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
  transform: translateY(0);
  opacity: 1;
  box-sizing: border-box;
  max-height: 52dvh;
}

/* Na komputerze w trybie symulatora telefonu klawiatura trzyma się obudowy */
html.device-desktop .game-virtual-keyboard,
body.device-desktop .game-virtual-keyboard {
  position: absolute;
}

/* Stan ukrycia (slide-down) */
.game-virtual-keyboard.gkb-hidden {
  transform: translateY(105%);
  opacity: 0;
  pointer-events: none;
}

/* ── 2. PASEK GÓRNY: PODGLĄD & KONTROLA ─────────────────────────────────────── */
.gkb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 4px 4px 4px;
  border-bottom: 2px solid #181824;
}

.gkb-preview-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  background: #110a22;
  border: 2px solid #181824;
  border-radius: 10px;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
  padding: 2px 8px;
  height: 34px;
}

.gkb-preview-clear {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  font-size: 1.05rem;
  font-weight: 800;
  padding: 2px 6px;
  min-height: 32px;
  min-width: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 8px;
  transition: all 0.12s ease;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.gkb-preview-clear:active {
  color: #ff4757;
  background: rgba(255, 71, 87, 0.15);
  transform: scale(1.1);
}

.gkb-field-badge {
  font-size: 0.72rem;
  font-weight: 900;
  font-family: var(--font-display, 'Titan One', cursive);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #181824;
  background: #ffd23f;
  border: 1.5px solid #181824;
  border-radius: 6px;
  padding: 2px 7px;
  white-space: nowrap;
  flex-shrink: 0;
}

.gkb-preview-content {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
}

.gkb-preview-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.5px;
}

.gkb-preview-text.is-empty {
  color: rgba(255, 255, 255, 0.35);
  font-weight: 500;
  font-style: italic;
  font-size: 0.9rem;
}

/* Kursor umieszczony na początku pustego pola */
.gkb-preview-content.is-empty .gkb-cursor,
.gkb-preview-wrap.is-empty .gkb-cursor {
  order: -1;
  margin-left: 0;
  margin-right: 4px;
}

.gkb-cursor {
  display: inline-block;
  width: 3px;
  height: 1.25em;
  background-color: #ffd23f;
  box-shadow: 0 0 6px rgba(255, 210, 63, 0.9);
  border-radius: 1px;
  margin-left: 2px;
  flex-shrink: 0;
  animation: gkbCursorBlink 0.85s infinite;
}

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

.gkb-controls {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.gkb-ctrl-btn {
  background: #271a48;
  border: 2px solid #181824;
  color: #ffffff;
  border-radius: 8px;
  height: 34px;
  min-width: 34px;
  padding: 0 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2.5px 0 #181824;
  transition: all 0.08s ease;
  -webkit-tap-highlight-color: transparent;
}

.gkb-ctrl-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #181824;
  background: #382467;
}

.gkb-field-nav {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: #110a22;
  border-radius: 10px;
  padding: 2px 4px;
  border: 2px solid #181824;
}

.gkb-field-counter {
  font-size: 0.75rem;
  font-weight: 800;
  color: #ffd23f;
  padding: 0 4px;
}

/* ── 3. RZĄD CYFR (1-TAP NA GÓRZE KLAWIATURY ZAMIAST POLSKICH ZNAKÓW) ─────── */
.gkb-numbers-strip,
.gkb-diacritics-strip {
  display: flex;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

.gkb-key-num-top,
.gkb-key-accent {
  flex: 1;
  min-width: 0;
  height: 38px;
  background: #241744;
  border: 2px solid #181824;
  border-radius: 8px;
  color: #ffd23f;
  font-size: 1.15rem;
  font-weight: 800;
  font-family: var(--font-display, 'Titan One', cursive);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 #181824;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.05s ease, background 0.05s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.gkb-key-num-top:active,
.gkb-key-num-top.is-pressed,
.gkb-key-accent:active,
.gkb-key-accent.is-pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #181824;
  background: #3e2774;
  color: #ffffff;
}

/* ── 4. UKŁAD QWERTY ────────────────────────────────────────────────────────── */
.gkb-layout-qwerty,
.gkb-layout-numpad {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gkb-row {
  display: flex;
  justify-content: center;
  gap: 4px;
  width: 100%;
}

.gkb-row-mid {
  padding: 0 2%;
}

/* Pojedynczy klawisz Jackbox Comic Block */
.gkb-key {
  flex: 1;
  height: 40px;
  min-width: 0;
  background: #2b1c52;
  color: #ffffff;
  border: 2px solid #181824;
  border-radius: 8px;
  font-size: 1.15rem;
  font-weight: 800;
  font-family: var(--font-display, 'Titan One', cursive);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 #181824;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.05s ease, background 0.05s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.gkb-key:active,
.gkb-key.is-pressed {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #181824;
  background: #3e2774;
}

/* Specjalne klawisze funkcjonalne */
.gkb-key-toggle {
  flex: 1.25;
  font-size: 0.9rem;
  font-weight: 800;
  color: #ffd23f;
  background: #20133e;
}

.gkb-key-backspace {
  flex: 1.35;
  background: #ff4757;
  color: #ffffff;
  font-size: 1.25rem;
}

.gkb-key-clear {
  flex: 0.9;
  max-width: 46px;
  background: #ff4757;
  color: #ffffff;
  font-size: 1.1rem;
}

.gkb-key-symbol {
  flex: 0.95;
  font-size: 1.25rem;
  font-weight: 800;
  color: #ffd23f;
  background: #20133e;
}

.gkb-key-punct {
  flex: 0.85;
  max-width: 48px;
  font-size: 1.3rem;
  color: #ffd23f;
  background: #20133e;
}

.gkb-key-space {
  flex: 3.2;
  font-size: 0.85rem;
  letter-spacing: 1.5px;
  color: rgba(255, 255, 255, 0.7);
  background: #1c1137;
}

/* Przycisk akcji (BUZZ! / Dalej / Zatwierdź) */
.gkb-key-action {
  flex: 2.3;
  background: #ffd23f;
  color: #181824;
  border: 2.5px solid #181824;
  font-size: 0.95rem;
  font-weight: 900;
  font-family: var(--font-display, 'Titan One', cursive);
  letter-spacing: 0.5px;
  box-shadow: 0 4px 0 #181824;
}

.gkb-key-action:active,
.gkb-key-action.is-pressed {
  transform: translateY(2.5px);
  box-shadow: 0 1.5px 0 #181824;
  background: #e6b820;
}

/* Wariant buzzera (Szybkie Palce) */
.gkb-key-action.is-buzz-mode {
  background: #ff4757;
  color: #ffffff;
  box-shadow: 0 4px 0 #181824;
}

.gkb-key-action.is-buzz-ready {
  animation: gkbBuzzPulse 1.2s infinite ease-in-out;
  will-change: transform;
}

@keyframes gkbBuzzPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.03);
    filter: brightness(1.1);
  }
}

.gkb-key-action.disabled,
.gkb-key-action[disabled] {
  opacity: 0.4;
  filter: grayscale(0.7);
  cursor: not-allowed;
  transform: none !important;
  box-shadow: 0 2px 0 #181824 !important;
}

/* ── 5. UKŁAD NUMERYCZNY (NUMPAD) ───────────────────────────────────────────── */
.gkb-layout-numpad .gkb-key-num {
  height: 48px;
  font-size: 1.45rem;
  font-weight: 800;
}

.gkb-key-action-num {
  flex: 3;
}

/* ── 6. PŁYWAJĄCA PIGUŁKA PRZYWRÓCENIA KLAWIATURY ────────────────────────────── */
.gkb-floating-pill {
  position: fixed;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  right: 14px;
  z-index: 990;
  display: flex;
  align-items: center;
}

html.device-desktop .gkb-floating-pill,
body.device-desktop .gkb-floating-pill {
  position: absolute;
}

.gkb-btn-restore {
  background: #ffd23f;
  border: 2.5px solid #181824;
  border-radius: 999px;
  color: #181824;
  padding: 8px 18px;
  font-size: 0.88rem;
  font-weight: 900;
  font-family: var(--font-display, 'Titan One', cursive);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 0 #181824, 0 8px 20px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.gkb-btn-restore:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #181824;
}

.gkb-restore-icon {
  font-size: 1.1rem;
}

/* ── 7. REGULACJA ROZMIARU EKRANÓW PRZY OTWARTEJ KLAWIATURZE ────────────────── */
#player-app-shell.keyboard-open .screen {
  padding-bottom: calc(275px + env(safe-area-inset-bottom, 0px)) !important;
}

/* Podświetlenie aktywnego pola w grze */
.form-input.gkb-active-field,
input.gkb-active-field {
  border-color: #ffd23f !important;
  border-width: 3.5px !important;
  box-shadow: 0 0 0 3.5px rgba(255, 210, 63, 0.45), 4px 4px 0 #181824 !important;
  background-color: #fffdf0 !important;
  color: #181824 !important;
  caret-color: #181824 !important;
}

/* ── 8. RESPONSYWNOŚĆ DLA BARDZO MAŁYCH LUB NISKICH EKRANÓW ──────────────────── */
@media (max-height: 680px) {
  .game-virtual-keyboard {
    padding: 4px 4px calc(6px + env(safe-area-inset-bottom, 0px)) 4px;
    gap: 3px;
  }
  .gkb-header {
    padding: 1px 2px 2px 2px;
  }
  .gkb-preview-wrap {
    height: 30px;
    padding: 1px 6px;
  }
  .gkb-ctrl-btn {
    height: 30px;
    min-width: 30px;
  }
  .gkb-key-num-top,
  .gkb-key-accent {
    height: 32px;
    font-size: 1rem;
  }
  .gkb-key {
    height: 34px;
    font-size: 1rem;
  }
  #player-app-shell.keyboard-open .screen {
    padding-bottom: calc(220px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

@media (max-width: 350px) {
  .game-virtual-keyboard {
    padding: 4px 3px calc(6px + env(safe-area-inset-bottom, 0px)) 3px;
    gap: 3px;
  }
  .gkb-key {
    height: 36px;
    font-size: 1rem;
  }
  .gkb-key-num-top,
  .gkb-key-accent {
    height: 30px;
    font-size: 0.95rem;
  }
  .gkb-action-label {
    font-size: 0.8rem;
  }
}
