/*--------------------------------------------------------------
# Typing Speed Test page
# Reuses .calc-card / .input-unit-wrap / .search-button /
# .reset-button / .result-unit-toggle / .unit-tab / .calc-error /
# .presets-panel / .presets-header / .presets-title / .file-count /
# .action-row from the shared style.css.
--------------------------------------------------------------*/
.typing-section { padding: 60px 0; }

/* ── Game card ─────────────────────────────────────────────────── */
.tt-card {
  /* Override the calc-card default 50px padding so the typing area
     gets the breathing room it needs without the toolbar feeling cramped. */
  padding: 32px 40px 36px;
}

/* Top toolbar: live stats on the left, duration tabs on the right */
.tt-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding-bottom: 22px;
  margin-bottom: 22px;
  border-bottom: 1px solid #eef0f2;
}
.tt-stats {
  display: flex;
  gap: 28px;
  flex-wrap: wrap;
}
.tt-stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.1;
}
.tt-stat-label {
  font-size: 11px;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 4px;
}
.tt-stat-value {
  font-family: "Poppins", sans-serif;
  font-size: 28px;
  font-weight: 700;
  color: #45505b;
  font-variant-numeric: tabular-nums;
  transition: color 0.2s;
}
.tt-stat-value.is-running {
  color: #0563bb;
}
.tt-stat-value.is-warning {
  color: #d97706;
}
.tt-stat-value.is-critical {
  color: #dc3545;
}

/* ── Typing target text ────────────────────────────────────────── */
.tt-text {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 22px;
  line-height: 1.7;
  color: #adb5bd;
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 8px;
  padding: 22px 26px;
  margin: 0 0 14px;
  word-spacing: 4px;
  letter-spacing: 0.2px;
  user-select: none;
  cursor: text;
  min-height: 120px;
  transition: border-color 0.15s, background 0.15s;
}
.tt-text:focus,
.tt-text.is-active {
  outline: none;
  border-color: #0563bb;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(5, 99, 187, 0.1);
}

/* Per-character states */
.tt-text .tt-char {
  position: relative;
  transition: color 0.05s;
}
.tt-text .tt-char.tt-correct { color: #28a745; }
.tt-text .tt-char.tt-wrong   { color: #dc3545; background: rgba(220, 53, 69, 0.12); border-radius: 2px; }
.tt-text .tt-char.tt-current {
  color: #45505b;
  background: rgba(5, 99, 187, 0.15);
  border-radius: 2px;
}
.tt-text .tt-char.tt-current::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 8%;
  bottom: 8%;
  width: 2px;
  background: #0563bb;
  animation: tt-blink 1s steps(1) infinite;
}
@keyframes tt-blink {
  50% { opacity: 0; }
}
/* Mark spaces clearly when wrong (otherwise invisible) */
.tt-text .tt-char.tt-wrong-space {
  background: rgba(220, 53, 69, 0.25);
}

/* The hidden textarea that actually receives keystrokes */
.tt-input {
  position: absolute;
  left: -9999px;
  width: 1px; height: 1px;
  opacity: 0;
}

.tt-hint {
  font-size: 13px;
  color: #6c757d;
  text-align: center;
  margin: 0 0 14px;
}

/* ── Result card ───────────────────────────────────────────────── */
.tt-result-card { margin-top: 24px; }
.tt-result-body { padding: 26px 28px 28px; }

.tt-result-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  flex-wrap: wrap;
  padding-bottom: 22px;
  margin-bottom: 22px;
  border-bottom: 1px solid #eef0f2;
}
.tt-result-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f8fafd;
  border: 1px solid #e4eaf1;
  border-radius: 10px;
  padding: 22px 32px;
  min-width: 130px;
}
.tt-result-num {
  font-family: "Poppins", sans-serif;
  font-size: 36px;
  font-weight: 700;
  color: #0563bb;
  font-variant-numeric: tabular-nums;
}
.tt-result-label {
  font-size: 12px;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 4px;
}

.tt-submit-form { max-width: 520px; margin: 0 auto; }

/* Submit-status flash */
.tt-submit-status {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 14px;
  text-align: center;
}
.tt-submit-status.is-success {
  background: #e8f5ee;
  color: #146c2e;
  border-left: 4px solid #28a745;
}
.tt-submit-status.is-error {
  background: #fff3f3;
  color: #dc3545;
  border-left: 4px solid #dc3545;
}

/* Inline spinner inside Submit Score button */
.tt-btn-label, .tt-btn-spinner {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tt-btn-spinner .bx { animation: tt-spin 0.8s linear infinite; }
@keyframes tt-spin { to { transform: rotate(360deg); } }
.search-button[aria-busy="true"] {
  pointer-events: none;
  opacity: 0.85;
}

/* ── Leaderboard ───────────────────────────────────────────────── */
.tt-leaderboard { margin-top: 24px; }
.tt-lb-body { padding: 4px 0 8px; }

.tt-lb-table {
  width: 100%;
  border-collapse: collapse;
}
.tt-lb-table thead th {
  font-size: 11px;
  font-weight: 700;
  color: #6c757d;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 28px;
  text-align: left;
  border-bottom: 1px solid #eef0f2;
}
.tt-lb-table tbody td {
  padding: 12px 28px;
  font-size: 14px;
  color: #45505b;
  border-bottom: 1px solid #f1f4f8;
  vertical-align: middle;
}
.tt-lb-table tbody tr:last-child td { border-bottom: none; }
.tt-lb-table tbody tr.is-self {
  background: rgba(5, 99, 187, 0.06);
  font-weight: 600;
}

.tt-lb-rank { width: 50px; }
.tt-lb-num  { width: 90px; text-align: right; font-variant-numeric: tabular-nums; }
.tt-lb-date { width: 130px; color: #6c757d; font-size: 12px; }
.tt-lb-empty {
  padding: 28px !important;
  text-align: center;
  color: #adb5bd;
  font-size: 14px;
}
.tt-lb-rank-medal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}
.tt-lb-rank-medal.r1 { background: #d4af37; }
.tt-lb-rank-medal.r2 { background: #aab2bd; }
.tt-lb-rank-medal.r3 { background: #cd7f32; }

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .tt-card { padding: 24px 20px 28px; }
  .tt-toolbar { gap: 14px; }
  .tt-stats { gap: 18px; }
  .tt-stat-value { font-size: 22px; }
  .tt-text { font-size: 18px; padding: 18px 18px; }
  .tt-result-body { padding: 22px 18px; }
  .tt-result-stat { padding: 18px 22px; min-width: 0; flex: 1; }
  .tt-result-num { font-size: 28px; }
  .tt-lb-table thead th, .tt-lb-table tbody td { padding: 10px 14px; }
  .tt-lb-date { display: none; }
}

@media (max-width: 480px) {
  .tt-result-stats { gap: 12px; }
  .tt-lb-num { width: 70px; }
}
