/**
 * TypingClub Typing Interface & Caret Stylesheet
 * Engineered for pixel-perfect cursor tracking, zero drift across wrapped lines,
 * high-contrast character states, and real-time statistics cards.
 */

.typing-section {
  padding: 2.5rem 0 3.5rem;
}

.typing-wrapper {
  max-width: 960px;
  margin: 0 auto;
}

/* Header & Meta */
.lesson-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.lesson-meta-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.lesson-tier-tag {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  background-color: var(--primary-light);
  color: var(--primary);
  text-transform: uppercase;
}

.lesson-diff-tag {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  background-color: var(--bg-tertiary);
  color: var(--text-muted);
}

.lesson-targets {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.lesson-targets span strong {
  color: var(--text-main);
}

/* Statistics Bar */
.typing-stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast);
}

.stat-box.stat-highlight {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-box.stat-highlight .stat-value {
  color: var(--primary);
}

/* Progress Track */
.typing-progress-track {
  width: 100%;
  height: 6px;
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.typing-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.15s ease-out;
  border-radius: var(--radius-full);
}

/* Main Typing Text Container */
.typing-text-container {
  position: relative;
  background-color: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem 2.25rem;
  font-family: var(--font-mono);
  font-size: 1.45rem;
  line-height: 2.0;
  letter-spacing: 0.02em;
  min-height: 210px;
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
  outline: none;
  cursor: text;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
  scrollbar-width: thin;
  scrollbar-color: var(--text-dim) var(--bg-tertiary);
}

.typing-text-container::-webkit-scrollbar {
  width: 8px;
}

.typing-text-container::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
}

.typing-text-container::-webkit-scrollbar-thumb {
  background: var(--text-dim);
  border-radius: var(--radius-full);
}

.typing-text-container::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

.typing-text-container:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px var(--primary-light);
}

/* Hidden Input for Keyboard Focus */
.typing-hidden-input {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: 0;
  border: none;
  pointer-events: none;
  clip: rect(0, 0, 0, 0);
  overflow: hidden;
}

/* Text & Characters Container */
.typing-text-wrapper {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  width: 100%;
  position: relative;
}

/* Individual Word wraps as an atomic unit to avoid split-word glitches */
.typing-word {
  display: inline-flex;
  white-space: pre;
  position: relative;
  flex-shrink: 0;
  margin-bottom: 0.25rem;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* Line break element for explicit \n newlines */
.typing-line-break {
  flex-basis: 100%;
  width: 100%;
  height: 0;
}

/* Individual Character */
.char {
  display: inline-block;
  position: relative;
  color: var(--text-dim);
  font-weight: 500;
  flex-shrink: 0;
  transition: color 0.05s ease, background-color 0.05s ease;
}

.char.char-space {
  display: inline-block;
  width: 0.52em;
  text-align: center;
  flex-shrink: 0;
}

.char.char-newline {
  display: inline-block;
  font-size: 0.8em;
  opacity: 0.45;
  margin-right: 0.25em;
  flex-shrink: 0;
}

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

.char.incorrect {
  color: var(--error);
  background-color: var(--error-bg);
  border-radius: 2px;
  text-decoration: underline 2px solid var(--error);
}

.char.current {
  color: var(--text-main);
  background-color: rgba(37, 99, 235, 0.08);
  border-radius: 2px;
}

/* Precision Character Caret / Cursor */
.typing-caret {
  position: absolute;
  top: 0;
  left: 0;
  width: 2.5px;
  background-color: var(--caret-color, #1d4ed8);
  border-radius: 2px;
  pointer-events: none;
  will-change: transform, height, opacity;
  transition: transform 0.07s cubic-bezier(0.1, 0.9, 0.2, 1), height 0.06s ease;
  box-shadow: 0 0 3px rgba(29, 78, 216, 0.4);
  animation: caretBlink 0.95s infinite;
  z-index: 10;
}

.typing-caret.typing {
  animation: none !important;
  opacity: 1 !important;
}

@keyframes caretBlink {
  0%, 48% {
    opacity: 1;
  }
  50%, 96% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}

/* Typing Controls Bar */
.typing-controls-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.typing-controls-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.typing-controls-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.hint-text {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Results Modal Overlay */
.results-modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1.5rem;
}

.results-modal-overlay.is-active {
  display: flex;
  animation: modalFadeIn 0.25s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.results-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  max-width: 580px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.res-header {
  margin-bottom: 1.75rem;
}

.res-title {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.res-badge-success {
  display: inline-block;
  padding: 0.4rem 1rem;
  background-color: var(--success-bg);
  color: var(--success);
  font-weight: 700;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
}

.res-badge-warning {
  display: inline-block;
  padding: 0.4rem 1rem;
  background-color: var(--bg-tertiary);
  color: var(--warning);
  font-weight: 700;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
}

.res-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.res-stat {
  background-color: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 1rem 0.75rem;
}

.res-stat.res-highlight {
  background-color: var(--primary-light);
  border: 1px solid rgba(37, 99, 235, 0.2);
}

.res-stat-val {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
}

.res-stat.res-highlight .res-stat-val {
  color: var(--primary);
}

.res-stat-lbl {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 0.2rem;
}

.res-details-row {
  display: flex;
  justify-content: space-around;
  padding: 0.75rem 0;
  border-top: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.75rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.res-details-row strong {
  color: var(--text-main);
}

.res-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Mobile Adjustments */
@media (max-width: 640px) {
  .typing-text-container {
    font-size: 1.25rem;
    line-height: 2;
    padding: 1.5rem;
    min-height: 180px;
  }
  .res-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ==========================================================================
   Custom Text Practice & Test Feature Styles
   ========================================================================== */

.practice-chips-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.practice-chips-container .category-chips-wrapper {
  margin-bottom: 0;
  flex: 1;
  min-width: 260px;
}

.custom-launcher-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: #ffffff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), opacity var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.custom-launcher-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
  color: #ffffff;
}

.custom-launcher-btn:active {
  transform: translateY(0);
}

/* Custom Text Modal */
.custom-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.custom-modal-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

.custom-modal-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 720px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  transform: scale(0.96) translateY(8px);
  transition: transform var(--transition-normal);
}

.custom-modal-overlay.is-active .custom-modal-card {
  transform: scale(1) translateY(0);
}

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

.custom-modal-title {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.custom-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  line-height: 1;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.custom-modal-close:hover {
  color: var(--text-main);
  background-color: var(--bg-tertiary);
}

.custom-form-group {
  margin-bottom: 1.25rem;
}

.custom-form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 0.5rem;
}

.custom-presets-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.custom-preset-btn {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border-radius: var(--radius-full);
  background-color: var(--bg-tertiary);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.custom-preset-btn:hover {
  background-color: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.custom-textarea {
  width: 100%;
  min-height: 170px;
  max-height: 320px;
  resize: vertical;
  background-color: var(--bg-primary);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--text-main);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  box-sizing: border-box;
}

.custom-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.custom-textarea::placeholder {
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

.custom-meta-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.custom-meta-counts {
  display: flex;
  gap: 1rem;
}

.custom-meta-counts strong {
  color: var(--text-main);
}

.custom-saved-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.custom-saved-header {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.custom-saved-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  max-height: 110px;
  overflow-y: auto;
}

.custom-saved-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-main);
  cursor: pointer;
  transition: border-color var(--transition-fast);
}

.custom-saved-pill:hover {
  border-color: var(--primary);
}

.custom-saved-del {
  color: var(--text-dim);
  cursor: pointer;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}

.custom-saved-del:hover {
  color: var(--error);
}

.custom-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.custom-active-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background-color: var(--primary-light);
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  border: 1px solid rgba(37, 99, 235, 0.2);
}
