/* Math Keyboard Component Styles */

.math-keyboard {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #f8f9fa;
  border-top: 2px solid var(--border-color);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
  z-index: 900;
  transform: translateY(100%);
  transition: transform 0.3s ease-in-out;
  max-height: 50vh;
  overflow-y: auto;
}

.math-keyboard.active {
  transform: translateY(0);
}

.math-keyboard-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}

/* Keyboard Header */
.keyboard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.keyboard-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.keyboard-tab {
  padding: 0.5rem 1rem;
  background-color: #e9ecef;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.keyboard-tab:hover {
  background-color: #dee2e6;
}

.keyboard-tab.active {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.keyboard-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
}

.keyboard-close:hover {
  background-color: #e9ecef;
  color: var(--text-primary);
}

/* Preview Area */
.keyboard-preview {
  background-color: white;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.keyboard-preview.has-content {
  border-color: var(--primary-color);
}

.keyboard-preview .katex {
  font-size: 1.5rem;
}

.keyboard-preview-placeholder {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 1rem;
}

/* Keyboard Grid */
.keyboard-grid {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.keyboard-mode {
  display: none;
}

.keyboard-mode.active {
  display: grid;
}

/* Number Keyboard Layout */
.keyboard-mode.number-mode {
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}

/* Fraction Keyboard Layout */
.keyboard-mode.fraction-mode {
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

/* Algebra Keyboard Layout */
.keyboard-mode.algebra-mode {
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(3, 1fr);
}

/* Keyboard Keys */
.keyboard-key {
  background-color: white;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  font-size: 1.25rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  min-width: 56px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.keyboard-key:hover {
  background-color: #f8f9fa;
  transform: translateY(-2px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.keyboard-key:active {
  transform: translateY(0);
  box-shadow: none;
}

/* Special Key Styles */
.keyboard-key.operator {
  background-color: #e3f2fd;
  color: var(--primary-color);
  font-weight: 600;
}

.keyboard-key.operator:hover {
  background-color: #bbdefb;
}

.keyboard-key.function {
  background-color: #f3e5f5;
  color: #7b1fa2;
  font-size: 1rem;
}

.keyboard-key.function:hover {
  background-color: #e1bee7;
}

.keyboard-key.control {
  background-color: #fff3e0;
  color: #e65100;
  font-size: 0.875rem;
}

.keyboard-key.control:hover {
  background-color: #ffe0b2;
}

.keyboard-key.delete {
  background-color: #ffebee;
  color: var(--danger-color);
}

.keyboard-key.delete:hover {
  background-color: #ffcdd2;
}

.keyboard-key.enter {
  background-color: var(--success-color);
  color: white;
  font-weight: 600;
  grid-column: span 2;
}

.keyboard-key.enter:hover {
  background-color: #15803d;
}

.keyboard-key.wide {
  grid-column: span 2;
}

/* Key Labels */
.keyboard-key .key-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.keyboard-key .key-main {
  font-size: 1.25rem;
}

.keyboard-key .key-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Input Display */
.keyboard-input-display {
  background-color: white;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  margin-bottom: 1rem;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  word-break: break-all;
}

.keyboard-input-display.focused {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.keyboard-input-cursor {
  display: inline-block;
  width: 2px;
  height: 1.2em;
  background-color: var(--primary-color);
  animation: blink 1s infinite;
  margin-left: 2px;
}

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

/* Action Buttons */
.keyboard-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

.keyboard-actions .btn {
  min-width: 100px;
}

/* Fraction Builder */
.fraction-builder {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-size: 1rem;
}

.fraction-builder .numerator {
  padding-bottom: 0.25rem;
  border-bottom: 2px solid currentColor;
}

.fraction-builder .denominator {
  padding-top: 0.25rem;
}

/* Special Symbols in Keys */
.keyboard-key .symbol {
  font-size: 1.5rem;
}

/* Keyboard Disabled State */
.math-keyboard.disabled {
  pointer-events: none;
  opacity: 0.6;
}

/* Touch Feedback */
@media (hover: none) {
  .keyboard-key:active {
    background-color: var(--primary-color);
    color: white;
    transform: scale(0.95);
  }
}

/* Responsive Adjustments */
@media (max-width: 768px) {
  .math-keyboard {
    max-height: 60vh;
  }

  .math-keyboard-container {
    padding: 0.75rem;
  }

  .keyboard-key {
    min-height: 48px;
    min-width: 48px;
    padding: 0.5rem;
    font-size: 1.1rem;
  }

  .keyboard-key .key-main {
    font-size: 1.1rem;
  }

  .keyboard-key .key-sub {
    font-size: 0.7rem;
  }

  .keyboard-preview {
    min-height: 50px;
    font-size: 1.25rem;
  }

  .keyboard-preview .katex {
    font-size: 1.25rem;
  }

  .keyboard-tabs {
    width: 100%;
  }

  .keyboard-tab {
    flex: 1;
    justify-content: center;
    font-size: 0.8rem;
    padding: 0.4rem 0.6rem;
  }
}

@media (max-width: 480px) {
  .keyboard-key {
    min-height: 44px;
    min-width: 44px;
    padding: 0.4rem;
    font-size: 1rem;
  }

  .keyboard-mode.number-mode,
  .keyboard-mode.fraction-mode,
  .keyboard-mode.algebra-mode {
    gap: 0.4rem;
  }
}

/* Landscape Mode on Mobile */
@media (max-width: 768px) and (orientation: landscape) {
  .math-keyboard {
    max-height: 80vh;
  }

  .keyboard-grid {
    gap: 0.4rem;
  }

  .keyboard-key {
    min-height: 40px;
    padding: 0.4rem;
  }
}

/* Accessibility */
.keyboard-key:focus-visible {
  outline: 3px solid var(--primary-color);
  outline-offset: 2px;
}

.keyboard-key[aria-pressed="true"] {
  background-color: var(--primary-color);
  color: white;
}

/* Print */
@media print {
  .math-keyboard {
    display: none !important;
  }
}
