/* Light Mode Theme Variables */
:root {
  --background: hsl(240, 4%, 98%);
  --foreground: hsl(220, 13%, 18%);
  --border: hsl(220, 13%, 88%);
  --card: hsl(0, 0%, 100%);
  --card-foreground: hsl(220, 13%, 18%);
  --card-border: hsl(220, 13%, 91%);
  --primary: hsl(217, 91%, 60%);
  --primary-foreground: hsl(0, 0%, 100%);
  --muted: hsl(240, 15%, 93%);
  --muted-foreground: hsl(220, 9%, 46%);
  --popover: hsl(240, 8%, 94%);
  --popover-foreground: hsl(220, 13%, 18%);
  --popover-border: hsl(240, 10%, 88%);
  
  --key-default: hsl(0, 0%, 95%);
  --key-default-foreground: hsl(220, 13%, 18%);
  --key-pressed: hsl(16, 100%, 50%);
  --key-pressed-foreground: hsl(0, 0%, 100%);
  --key-shadow: hsl(220, 13%, 75%);
  --key-border: hsl(220, 13%, 85%);
  
  --elevate-1: rgba(0, 0, 0, 0.03);
  --elevate-2: rgba(0, 0, 0, 0.08);
}

/* Dark Mode Theme Variables */
.dark {
  --background: hsl(222, 47%, 11%);
  --foreground: hsl(210, 20%, 98%);
  --border: hsl(217, 15%, 25%);
  --card: hsl(223, 39%, 15%);
  --card-foreground: hsl(210, 20%, 98%);
  --card-border: hsl(223, 35%, 18%);
  --primary: hsl(217, 91%, 65%);
  --primary-foreground: hsl(210, 20%, 98%);
  --muted: hsl(223, 30%, 20%);
  --muted-foreground: hsl(217, 10%, 70%);
  --popover: hsl(223, 35%, 18%);
  --popover-foreground: hsl(210, 20%, 98%);
  --popover-border: hsl(223, 30%, 22%);
  
  --key-default: hsl(223, 30%, 22%);
  --key-default-foreground: hsl(210, 20%, 98%);
  --key-pressed: hsl(16, 100%, 55%);
  --key-pressed-foreground: hsl(210, 20%, 98%);
  --key-shadow: hsl(223, 40%, 8%);
  --key-border: hsl(223, 30%, 28%);
  
  --elevate-1: rgba(255, 255, 255, 0.04);
  --elevate-2: rgba(255, 255, 255, 0.09);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--background);
  color: var(--foreground);
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1600px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.title {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--foreground);
}

.subtitle {
  font-size: 1rem;
  color: var(--muted-foreground);
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Layout Switcher */
.layout-switcher {
  position: relative;
}

.layout-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--card-border);
  border-radius: 0.375rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  min-width: 180px;
  transition: all 0.2s ease;
}

.layout-button:hover {
  background-color: var(--elevate-1);
}

.layout-button .label {
  font-weight: 500;
  color: var(--muted-foreground);
}

.layout-button .value {
  flex: 1;
  text-align: left;
  font-family: 'JetBrains Mono', monospace;
}

.layout-button .chevron {
  transition: transform 0.2s ease;
}

.layout-switcher.open .chevron {
  transform: rotate(180deg);
}

.dropdown {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  width: 100%;
  background-color: var(--popover);
  border: 1px solid var(--popover-border);
  border-radius: 0.375rem;
  box-shadow: 0 10px 24px -6px rgba(0, 0, 0, 0.15), 0 8px 16px -4px rgba(0, 0, 0, 0.1);
  z-index: 50;
  overflow: hidden;
  display: none;
}

.layout-switcher.open .dropdown {
  display: block;
}

.dropdown-item {
  width: 100%;
  padding: 0.625rem 1rem;
  text-align: left;
  background: none;
  border: none;
  color: var(--popover-foreground);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.dropdown-item:hover {
  background-color: var(--elevate-1);
}

.dropdown-item.active {
  font-weight: 600;
  color: var(--primary);
}

/* Size Switcher */
.size-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background-color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
}

.size-label {
  padding: 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

.size-buttons {
  display: flex;
  gap: 0.25rem;
}

.size-button {
  padding: 0.375rem 0.75rem;
  background: none;
  border: none;
  border-radius: 0.25rem;
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.size-button:hover {
  background-color: var(--elevate-1);
}

.size-button.active {
  background-color: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Reset Button */
.reset-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background-color: var(--muted);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

.reset-button:hover {
  background-color: var(--elevate-2);
}

.reset-button svg {
  width: 16px;
  height: 16px;
}

/* Mode Switcher */
.mode-switcher {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  background-color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
}

.mode-label {
  padding: 0 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

.mode-buttons {
  display: flex;
  gap: 0.25rem;
}

.mode-button {
  padding: 0.375rem 0.75rem;
  background: none;
  border: none;
  border-radius: 0.25rem;
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.mode-button:hover {
  background-color: var(--elevate-1);
}

.mode-button.active {
  background-color: var(--primary);
  color: var(--primary-foreground);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Sound Toggle Button */
.sound-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  background-color: var(--muted);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 2.5rem;
  height: 2.5rem;
}

.sound-toggle:hover {
  background-color: var(--elevate-2);
}

.sound-toggle.muted {
  opacity: 0.5;
}

.sound-toggle svg {
  width: 16px;
  height: 16px;
}

@media (max-width: 768px) {
  .mode-switcher{
    flex-direction: column;
    order: 1;
  }
  .layout-switcher{
    order: 3;
  }
  .size-switcher{
    order: 2;
  }
}

/* Theme Toggle */
.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  height: 2.25rem;
  width: 4rem;
  background-color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.theme-toggle:hover {
  background-color: var(--elevate-1);
}

.toggle-slider {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 1.75rem;
  width: 1.75rem;
  background-color: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 9999px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  transform: translateX(0.25rem);
}

.dark .toggle-slider {
  transform: translateX(2rem);
}

.icon {
  width: 1rem;
  height: 1rem;
  color: var(--foreground);
}

.sun-icon {
  display: block;
}

.moon-icon {
  display: none;
}

.dark .sun-icon {
  display: none;
}

.dark .moon-icon {
  display: block;
}

/* Status Indicator */
.status-indicator {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.status-text {
  padding: 0.75rem 1.5rem;
  background-color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.875rem;
  text-align: center;
}

.status-hint {
  color: var(--muted-foreground);
}

.status-key {
  color: var(--primary);
  font-weight: 600;
}

/* Main Content - Keyboard and History Stacked */
.main-content {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  align-items: flex-start;
  justify-items: center;
}

/* Keyboard Wrapper - allows horizontal scroll on mobile */
.keyboard-wrapper {
  width: 100%;
  display: flex;
  justify-content: center;
  overflow: visible;
}

.keyboard-scroll-container {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  padding: 0.5rem;
}

/* Hide scrollbar but keep functionality */
.keyboard-scroll-container::-webkit-scrollbar {
  height: 6px;
}

.keyboard-scroll-container::-webkit-scrollbar-track {
  background: transparent;
}

.keyboard-scroll-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.keyboard-scroll-container::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

/* Keyboard Container */
.keyboard-container {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  padding: 2rem;
  background-color: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 1rem;
  outline: none;
  transition: all 0.3s ease;
  box-shadow: 0 10px 24px -6px rgba(0, 0, 0, 0.1), 0 8px 16px -4px rgba(0, 0, 0, 0.08);
}
/*
.keyboard-container:focus {
  border-color: var(--primary);
  box-shadow: 0 10px 24px -6px rgba(0, 0, 0, 0.15), 
              0 8px 16px -4px rgba(0, 0, 0, 0.1),
              0 0 0 4px hsla(217, 91%, 60%, 0.2);
}

.keyboard-container.focused {
  border-color: var(--primary);
  box-shadow: 0 10px 24px -6px rgba(0, 0, 0, 0.15), 
              0 8px 16px -4px rgba(0, 0, 0, 0.1),
              0 0 0 4px hsla(217, 91%, 60%, 0.2);
}
*/
.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.keyboard-row {
  display: flex;
  justify-content: center;
}

/* Key Styles */
.key {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0.125rem;
  padding: 0;
  background-color: var(--key-default);
  color: var(--key-default-foreground);
  border: 2px solid var(--key-border);
  border-radius: 0.375rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: default;
  user-select: none;
  transition: all 0.1s ease;
  box-shadow: 
    0 2px 0 var(--key-border),
    0 4px 0 var(--key-shadow),
    0 6px 8px rgba(0, 0, 0, 0.15),
    0 8px 16px rgba(0, 0, 0, 0.1);
}

.key:hover {
  transform: translateY(-2px);
  box-shadow: 
    0 4px 0 var(--key-border),
    0 6px 0 var(--key-shadow),
    0 8px 10px rgba(0, 0, 0, 0.2),
    0 10px 18px rgba(0, 0, 0, 0.12);
}

.key.pressed {
  background-color: var(--key-pressed);
  color: var(--key-pressed-foreground);
  border-color: var(--key-pressed);
  transform: translateY(4px) scale(0.98);
  box-shadow: 
    0 2px 4px rgba(0, 0, 0, 0.2);
}

.key span {
  position: relative;
  z-index: 10;
  pointer-events: none;
}

/* History Panel */
.history-panel {
  width: 100%;
  max-width: 900px;
  background-color: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: 0 10px 24px -6px rgba(0, 0, 0, 0.1), 0 8px 16px -4px rgba(0, 0, 0, 0.08);
  max-height: 600px;
  display: flex;
  flex-direction: column;
}

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

@media (max-width: 768px) {
  .history-header{
    flex-direction: column;
  }
}

.history-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--foreground);
}

.history-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.action-button {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background-color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 0.375rem;
  color: var(--primary-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.action-button:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.action-button svg {
  width: 14px;
  height: 14px;
}

.clear-button {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  background-color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  color: var(--foreground);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.clear-button:hover {
  background-color: var(--elevate-2);
}

.clear-button svg {
  width: 14px;
  height: 14px;
}

.history-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.frequency-graph {
  width: 100%;
  height: 300px;
  background-color: var(--muted);
  border-radius: 0.5rem;
  padding: 0.5rem;
}

.history-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.625rem 0.875rem;
  background-color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.75rem;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.history-item-key {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.history-item-label {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 600;
  color: var(--primary);
  font-size: 0.875rem;
}

.history-item-code {
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted-foreground);
  font-size: 0.625rem;
}

.history-item-time {
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted-foreground);
  font-size: 0.625rem;
}

/* Accessibility Hint */
.accessibility-hint {
  margin-top: 1.5rem;
  text-align: center;
}

.accessibility-hint p {
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

/* Mobile Responsive Design */
@media (max-width: 1280px) {
  .container {
    padding: 1.5rem 1rem;
  }
  
  .title {
    font-size: 2rem;
  }
}

@media (max-width: 1024px) {
  .title {
    font-size: 1.75rem;
  }
  
  .controls {
    justify-content: center;
  }

  .main-content {
    grid-template-columns: 1fr;
  }

  .history-panel {
    width: 100%;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 1rem 0.5rem;
  }
  
  .title {
    font-size: 1.5rem;
  }
  
  .subtitle {
    font-size: 0.875rem;
  }
  
  .control-group {
    width: 100%;
    justify-content: center;
  }
  
  .layout-button {
    min-width: 140px;
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
  }

  .reset-button {
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
  }

  .reset-button svg {
    width: 14px;
    height: 14px;
  }

  .main-content{
    justify-content:center;
    display: flex;
    flex-direction: column;
  }
  
  .keyboard-container {
    padding: 1rem;
  }

  .keyboard-scroll-container {
    padding: 0.25rem;
  }
  
  .size-switcher {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .size-buttons {
    flex-wrap: wrap;
  }

  .size-button {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
  }

  /* Mobile key optimizations - smaller keys */
  .key {
    font-size: 0.625rem !important;
    border-width: 1px;
    box-shadow: 
      0 1px 0 var(--key-border),
      0 2px 0 var(--key-shadow),
      0 3px 4px rgba(0, 0, 0, 0.1);
  }

  .key:hover {
    box-shadow: 
      0 2px 0 var(--key-border),
      0 3px 0 var(--key-shadow),
      0 4px 5px rgba(0, 0, 0, 0.15);
  }

  .key.pressed {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .history-panel {
    padding: 1rem;
    max-width: 370px;
  }

  .history-title {
    font-size: 1rem;
  }

  .history-item {
    padding: 0.5rem 0.625rem;
    font-size: 0.625rem;
  }

  .history-item-label {
    font-size: 0.75rem;
  }
}

/* Mobile-specific short labels */
@media (max-width: 480px) {
  .key {
    font-size: 0.5rem !important;
  }

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

  .size-label {
    font-size: 0.75rem;
  }
/*
  .Size100{
    margin-left: -3px;
  }
  .Size100 .key{
    width: 14px !important;
    height: 19px !important;
    border-radius: 4px;
    font-size: 0.45rem !important;
  }*/
}

@media (max-width: 400px) {
  .Size100{
    margin-left: -4px !important;
  }
  .key{
    border-radius: 4px !important;
  }
}


#typingParagraph{
  white-space: normal;
  word-break: break-word;
}

.SizeTKL .keyboard-row,
.Size100 .keyboard-row{
	width:100% !important;
	justify-content: flex-start !important;
}
.SizeTKL .keyboard-row:nth-child(1) .key:nth-child(1){
	margin-right:auto !important;
}
.SizeTKL .keyboard-row:nth-child(1) .key:nth-child(2){
	margin-left:auto !important;
}
.SizeTKL .keyboard-row:nth-child(1) .key:nth-child(5){
	margin-right:auto !important;
}
.SizeTKL .keyboard-row:nth-child(1) .key:nth-child(6){
	margin-left:auto !important;
}
.SizeTKL .keyboard-row:nth-child(1) .key:nth-child(9){
	margin-right:auto !important;
}
.SizeTKL .keyboard-row:nth-child(1) .key:nth-child(10){
	margin-left:auto !important;
}


.SizeTKL .keyboard-row:nth-child(5) .key:last-child{
	margin-left:auto !important;
	margin-right:auto !important;
}


.SizeTKL .keyboard-row:nth-child(6) .key:nth-child(8){
	margin-right:auto !important;
}




.Size100 .keyboard-row:nth-child(1) .key:nth-child(1){
	margin-right:auto !important;
}
.Size100 .keyboard-row:nth-child(1) .key:nth-child(2){
	margin-left:auto !important;
}
.Size100 .keyboard-row:nth-child(1) .key:nth-child(5){
	margin-right:auto !important;
}
.Size100 .keyboard-row:nth-child(1) .key:nth-child(6){
	margin-left:auto !important;
}
.Size100 .keyboard-row:nth-child(1) .key:nth-child(9){
	margin-right:auto !important;
}
.Size100 .keyboard-row:nth-child(1) .key:nth-child(10){
	margin-left:auto !important;
}

.Size100 .keyboard-row:nth-child(1) .key:nth-child(17),
.Size100 .keyboard-row:nth-child(1) .key:nth-child(18),
.Size100 .keyboard-row:nth-child(1) .key:nth-child(19),
.Size100 .keyboard-row:nth-child(1) .key:nth-child(20){
	opacity:0;
}


.Size100 .keyboard-row:nth-child(4) .key:nth-child(13){
	margin-right:auto !important;
}
.Size100 .keyboard-row:nth-child(4) .key:last-child{
	opacity:0 !important;
}

.Size100 .keyboard-row:nth-child(5) .key:nth-child(13){
	margin-left:auto !important;
	margin-right:auto !important;
}


.Size100 .keyboard-row:nth-child(6) .key:last-child{
	opacity:0 !important;
}

.Size100 .keyboard-row:nth-child(6) .key:nth-child(8){
	margin-right:auto !important;
}
.Size100 .keyboard-row:nth-child(6) .key:nth-child(9){
	margin-left:auto !important;
}
.Size100 .keyboard-row:nth-child(6) .key:nth-child(11){
	margin-right:auto !important;
}