/**
 * TypingClub On-Screen QWERTY Keyboard Stylesheet
 * Engineered with a mathematical 15-unit (15u) row system.
 * Guarantees pixel-perfect column alignment, authentic mechanical keycap depth,
 * responsive scaling across mobile/tablet/desktop, and vibrant next-key guidance.
 */

.keyboard-section {
  margin-top: 2rem;
  width: 100%;
}

.virtual-keyboard {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
  box-sizing: border-box;
}

.virtual-keyboard.is-hidden {
  display: none !important;
}

/* 15u Row Container */
.kb-row {
  display: flex;
  width: 100%;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
  box-sizing: border-box;
}

.kb-row:last-child {
  margin-bottom: 0;
}

/* Individual Keycaps */
.kb-key {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 50px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-bottom: 3px solid rgba(0, 0, 0, 0.16);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  font-weight: 700;
  text-align: center;
  box-sizing: border-box;
  overflow: hidden;
  transition: transform 0.06s ease, background-color 0.1s ease, border-color 0.1s ease, box-shadow 0.1s ease;
}

[data-theme="dark"] .kb-key {
  border-bottom: 3px solid rgba(0, 0, 0, 0.45);
}

/* Mathematical 15-Unit (15u) System */
.kb-u-1    { flex: 1 1 0%; min-width: 0; }
.kb-u-1-25 { flex: 1.25 1 0%; min-width: 0; }
.kb-u-1-5  { flex: 1.5 1 0%; min-width: 0; }
.kb-u-1-75 { flex: 1.75 1 0%; min-width: 0; }
.kb-u-2    { flex: 2 1 0%; min-width: 0; }
.kb-u-2-25 { flex: 2.25 1 0%; min-width: 0; }
.kb-u-2-75 { flex: 2.75 1 0%; min-width: 0; }
.kb-u-6-25 { flex: 6.25 1 0%; min-width: 0; }

/* Functional / Modifier Keys */
.kb-key-func {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  background-color: rgba(0, 0, 0, 0.02);
}

[data-theme="dark"] .kb-key-func {
  background-color: rgba(255, 255, 255, 0.03);
}

/* Dual-character sub/main labels */
.kb-key .k-sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1;
  margin-bottom: 2px;
}

.kb-key .k-main {
  font-size: 0.88rem;
  line-height: 1;
  font-weight: 700;
}

.kb-key .k-letter {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1;
}

.kb-key .k-space-text {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* Tactile bumps for F and J home row anchors */
.kb-bump::after {
  content: '';
  position: absolute;
  bottom: 6px;
  width: 14px;
  height: 2px;
  background-color: var(--text-muted);
  border-radius: 1px;
}

/* Next Expected Key Glow */
.kb-key.kb-next {
  background-color: var(--primary-light) !important;
  border-color: var(--primary) !important;
  border-bottom: 3px solid var(--primary) !important;
  color: var(--primary) !important;
  box-shadow: 0 0 14px rgba(37, 99, 235, 0.5) !important;
  transform: translateY(-2px);
  animation: nextKeyPulse 1.1s infinite alternate;
}

@keyframes nextKeyPulse {
  0% { transform: translateY(-2px); box-shadow: 0 0 8px rgba(37, 99, 235, 0.35); }
  100% { transform: translateY(-3px); box-shadow: 0 0 16px rgba(37, 99, 235, 0.75); }
}

/* Shift Key Glow when capital/symbol required */
.kb-key.kb-next-shift {
  background-color: rgba(6, 182, 212, 0.18) !important;
  border-color: var(--accent) !important;
  border-bottom: 3px solid var(--accent) !important;
  color: var(--accent) !important;
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.5) !important;
  transform: translateY(-1px);
}

/* Real-Time Keystroke Flash Animations */
.kb-key.kb-correct {
  background-color: var(--success) !important;
  color: #ffffff !important;
  border-color: var(--success) !important;
  border-bottom-width: 1px !important;
  transform: translateY(2px) scale(0.98);
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6) !important;
}

.kb-key.kb-error {
  background-color: var(--error) !important;
  color: #ffffff !important;
  border-color: var(--error) !important;
  border-bottom-width: 1px !important;
  transform: translateY(2px) scale(0.98);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.7) !important;
}

/* Responsive Scaling: Tablet */
@media (max-width: 768px) {
  .virtual-keyboard {
    padding: 0.75rem 0.5rem;
  }
  .kb-row {
    gap: 0.2rem;
    margin-bottom: 0.2rem;
  }
  .kb-key {
    height: 38px;
    font-size: 0.8rem;
    border-bottom-width: 2px;
  }
  .kb-key .k-sub {
    font-size: 0.55rem;
    margin-bottom: 1px;
  }
  .kb-key .k-main, .kb-key .k-letter {
    font-size: 0.78rem;
  }
  .kb-key-func {
    font-size: 0.62rem;
  }
  .kb-bump::after {
    width: 10px;
    bottom: 4px;
  }
}

/* Responsive Scaling: Mobile */
@media (max-width: 480px) {
  .virtual-keyboard {
    padding: 0.5rem 0.35rem;
  }
  .kb-row {
    gap: 0.15rem;
    margin-bottom: 0.15rem;
  }
  .kb-key {
    height: 32px;
    border-radius: 4px;
    border-bottom-width: 2px;
  }
  .kb-key .k-sub {
    display: none; /* Hide top symbol on very small screens for clarity */
  }
  .kb-key .k-main, .kb-key .k-letter {
    font-size: 0.72rem;
  }
  .kb-key-func {
    font-size: 0.55rem;
  }
}
