/* Typing Test drill interfaces stylesheet */

/* Beginner Lesson Space Variables */
:root {
  --beginner-box-padding: 0.1rem 0.25rem;
  --beginner-box-margin-bottom: 2.25rem;
  --beginner-header-margin-bottom: 1.5rem;
  --beginner-key-gap: 0.4rem;
  --beginner-box-height: 76px;
}

.beginner-drill-view .beginner-header-row {
  margin-bottom: var(--beginner-header-margin-bottom) !important;
}

.beginner-drill-view #typing-box-container {
  padding: var(--beginner-box-padding) !important;
  margin-bottom: var(--beginner-box-margin-bottom) !important;
  height: var(--beginner-box-height) !important;
  min-height: var(--beginner-box-height) !important;
}

.beginner-drill-view .key-drill-row {
  gap: var(--beginner-key-gap) !important;
}

/* Metric box blocks */
.metric-square {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  transition: var(--transition-normal);
}

.metric-square:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metric-icon-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.metric-icon-circle svg {
  width: 14px;
  height: 14px;
}

.metric-lbl {
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  line-height: 1;
  margin-bottom: 0.15rem;
}

.metric-val {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
}

/* Typing text area pane */
.drill-text-pane {
  font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  font-size: 1.8rem;
  line-height: 1.5;
  color: var(--text-light);
  user-select: none;
  min-height: 120px;
  word-wrap: break-word;
  white-space: pre-wrap;
  transition: var(--transition-normal);
  outline: none;
  position: relative !important; /* Contain smooth caret */
  scrollbar-width: none; /* Hide scrollbar Firefox */
  -ms-overflow-style: none; /* Hide scrollbar IE/Edge */
}

.drill-text-pane::-webkit-scrollbar {
  display: none !important; /* Hide scrollbar Chrome/Safari/Opera */
  width: 0 !important;
  height: 0 !important;
}

.beginner-drill-view .drill-text-pane {
  min-height: auto !important;
  max-height: none !important;
  height: auto !important;
  overflow: visible !important;
  padding-bottom: 0 !important;
}

.drill-char {
  position: relative;
  border-bottom: 2px solid transparent;
  border-left: 2.5px solid transparent; /* Prevent layout shifts */
  transition: var(--transition-fast);
  padding: 0 1px;
}

.drill-caret {
  position: absolute;
  width: 2.5px;
  background-color: var(--primary);
  transition: left 0.11s cubic-bezier(0.1, 0.9, 0.2, 1), top 0.11s ease, height 0.11s ease;
  pointer-events: none;
  animation: caretBlink 1s step-end infinite;
  z-index: 5;
}

/* Character states */
.drill-char.current {
  color: var(--text-main);
  background: transparent !important;
  border-bottom-color: transparent !important;
}

.drill-char.correct {
  color: var(--primary);
}

.drill-char.incorrect {
  color: var(--error);
  background: var(--error-light);
  border-bottom-color: var(--error);
}

.drill-char.space.incorrect {
  background: var(--error-light);
  border-bottom: 2px solid var(--error);
}

@keyframes caretBlink {
  50% { border-left-color: transparent !important; }
}

/* Virtual Keyboard styling */
.virtual-keyboard {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.kbd-row {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
}

.kbd-key {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 8px;
  height: 42px;
  min-width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-main);
  cursor: default;
  user-select: none;
  transition: var(--transition-fast);
  font-family: var(--font-title);
  box-shadow: 0 2px 0 var(--border);
}

/* Sizing variations */
.kbd-key.backspace { min-width: 80px; }
.kbd-key.tab { min-width: 60px; }
.kbd-key.caps-lock { min-width: 85px; }
.kbd-key.enter { min-width: 80px; }
.kbd-key.shift { min-width: 100px; }
.kbd-key.space { min-width: 320px; }
.kbd-key.ctrl, .kbd-key.win, .kbd-key.alt { min-width: 48px; }

/* Active States */
.kbd-key.target {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 3px 0 hsl(var(--primary-hue), 85%, 45%), 0 6px 12px rgba(114, 55, 239, 0.4);
  animation: keyPulse 1.2s infinite;
}

.kbd-key.error-press {
  background: var(--error) !important;
  color: white !important;
  border-color: var(--error) !important;
  box-shadow: 0 3px 0 hsl(0, 85%, 45%), 0 6px 12px rgba(231, 76, 60, 0.4);
  animation: shake 0.2s ease;
}

@keyframes keyPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.03); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* 10-Key Cap Visualizer (Beginner Key Drills) */
.key-drill-container {
  text-align: center;
  margin: 0;
  padding: 0.5rem 0;
}

.compact-metric {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.55rem;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  line-height: 1;
}

.key-drill-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 1.2rem;
}

.key-drill-row {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.drill-key-cap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  height: 54px;
  min-width: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text-main);
  box-shadow: 0 4px 0 var(--border);
  transition: all 0.1s ease;
  user-select: none;
}

.drill-key-cap.space {
  min-width: 140px;
}

.drill-key-cap.enter {
  min-width: 120px;
}

.drill-key-cap.active {
  background: var(--primary);
  color: white !important;
  border-color: var(--primary);
  box-shadow: 0 2px 0 hsl(258, 85%, 45%), 0 6px 12px rgba(114, 55, 239, 0.35);
  transform: translateY(2px);
}

/* Typing Test Filters & Config Row */
.test-config-row {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.test-config-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.test-config-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.tab-group {
  display: flex;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.25rem;
  gap: 0.2rem;
}

.tab-item {
  background: transparent;
  border: none;
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-item:hover {
  color: var(--text-main);
  background: rgba(114, 55, 239, 0.05);
}

.tab-item.active {
  background: var(--primary);
  color: white !important;
}

/* Typing Test overlay start card */
.test-start-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: hsl(var(--primary-hue), 85%, 98%);
  border: 1.5px dashed hsla(var(--primary-hue), 85%, 85%, 0.7);
  border-radius: 12px;
  padding: 1rem 2rem;
  margin: 1.5rem auto 0 auto;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  animation: overlayPulse 2s infinite ease-in-out;
}

.test-start-overlay-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.test-start-overlay-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

@keyframes overlayPulse {
  0%, 100% { transform: translateY(0); box-shadow: var(--shadow-sm); }
  50% { transform: translateY(-3px); box-shadow: 0 8px 15px rgba(114, 55, 239, 0.1); }
}

/* Test Metrics Container Grid */
.test-metrics-grid {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ================= TYPING TEST RESPONSIVE BREAKPOINTS ================= */

/* Laptop L & Desktop (1440px and above) */
@media (min-width: 1440px) {
  .virtual-keyboard {
    max-width: 900px;
  }
}

/* Laptop & Tablet Landscape (1024px) */
@media (max-width: 1024px) {
  .drill-text-pane {
    font-size: 1.6rem;
  }

  .virtual-keyboard {
    max-width: 780px;
  }
}

/* Tablet (768px) */
@media (max-width: 768px) {
  .drill-text-pane {
    font-size: 1.35rem;
    min-height: 85px;
    max-height: 175px;
    overflow-y: auto;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2.5rem;
    line-height: 1.6;
  }

  .test-config-row {
    flex-direction: column;
    gap: 1rem;
  }

  .test-metrics-grid {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 0.35rem !important;
    width: 100% !important;
  }

  .test-metrics-grid .metric-square {
    padding: 0.4rem 0.25rem !important;
    gap: 0.3rem !important;
    justify-content: center !important;
    text-align: center !important;
    min-width: 0 !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .test-metrics-grid .metric-icon-circle {
    width: 22px !important;
    height: 22px !important;
    flex-shrink: 0 !important;
  }

  .test-metrics-grid .metric-icon-circle svg {
    width: 11px !important;
    height: 11px !important;
  }

  .test-metrics-grid .metric-lbl {
    font-size: 0.55rem !important;
    letter-spacing: 0 !important;
    white-space: nowrap !important;
    line-height: 1 !important;
  }

  .test-metrics-grid .metric-val {
    font-size: 0.92rem !important;
    line-height: 1 !important;
  }

  .test-config-group {
    width: 100% !important;
  }

  .tab-group {
    display: flex !important;
    width: 100% !important;
    justify-content: space-between !important;
  }

  .tab-item {
    flex: 1 !important;
    text-align: center !important;
    padding: 0.4rem 0.3rem !important;
    font-size: 0.78rem !important;
    white-space: nowrap !important;
  }

  .virtual-keyboard {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem 0.5rem;
  }

  .kbd-row {
    width: max-content;
    margin: 0 auto;
  }

  .key-drill-row {
    gap: 0.35rem !important;
  }

  .drill-key-cap {
    height: 38px;
    min-width: 32px;
    font-size: 0.9rem;
    border-radius: 8px;
    padding: 0 4px;
  }

  .drill-key-cap.space { min-width: 65px; font-size: 0.75rem; }
  .drill-key-cap.enter { min-width: 60px; font-size: 0.75rem; }

  #typing-box-container {
    height: auto !important;
    min-height: 70px !important;
    overflow: visible !important;
  }

  .beginner-drill-view #typing-box-container {
    min-height: 56px !important;
    height: auto !important;
    padding: 0.25rem 0 !important;
    margin-bottom: 1.5rem !important;
  }
}

/* Mobile L (425px) */
@media (max-width: 425px) {
  .drill-text-pane {
    font-size: 1.2rem;
    line-height: 1.5;
  }

  .test-metrics-grid {
    gap: 0.25rem !important;
  }

  .test-metrics-grid .metric-square {
    padding: 0.35rem 0.15rem !important;
    gap: 0.2rem !important;
  }

  .test-metrics-grid .metric-icon-circle {
    display: none !important; /* Hide icon circle on small screens for 1-line fit */
  }

  .test-metrics-grid .metric-lbl {
    font-size: 0.52rem !important;
  }

  .test-metrics-grid .metric-val {
    font-size: 0.88rem !important;
  }

  .test-start-overlay {
    padding: 0.85rem 1rem;
    max-width: 100%;
  }

  .test-config-label {
    font-size: 0.68rem !important;
  }

  .tab-group {
    padding: 0.15rem !important;
    gap: 0.15rem !important;
  }

  .tab-item {
    padding: 0.35rem 0.25rem !important;
    font-size: 0.72rem !important;
  }
}

/* Mobile M (375px) */
@media (max-width: 375px) {
  .drill-text-pane {
    font-size: 1.1rem;
    min-height: 75px;
  }

  .test-start-overlay-title {
    font-size: 0.88rem;
  }

  .test-start-overlay-sub {
    font-size: 0.72rem;
  }
}

/* Mobile S (320px) */
@media (max-width: 320px) {
  .drill-text-pane {
    font-size: 1.0rem;
    line-height: 1.45;
    min-height: 65px;
  }

  .test-metrics-grid .metric-lbl {
    font-size: 0.46rem !important;
  }

  .test-metrics-grid .metric-val {
    font-size: 0.8rem !important;
  }

  .tab-item {
    padding: 0.3rem 0.15rem !important;
    font-size: 0.68rem !important;
  }

  .test-start-overlay {
    padding: 0.65rem 0.75rem;
  }
}
