
:root {
  --bg: #0d0f14;
  --surface: #13161d;
  --surface2: #1a1e28;
  --border: #252836;
  --border2: #2e3347;
  --text: #e8eaf0;
  --text-dim: #6b7280;
  --text-muted: #3d4459;
  --accent: #7c6aff;
  --accent-dim: rgba(124, 106, 255, 0.12);
  --accent-glow: rgba(124, 106, 255, 0.25);
  --green: #34d399;
  --green-dim: rgba(52, 211, 153, 0.12);
  --red: #f87171;
  --red-dim: rgba(248, 113, 113, 0.15);
  --yellow: #fbbf24;
  --radius: 10px;
  --radius-lg: 16px;
  --mono: 'JetBrains Mono', 'Fira Code', monospace;
  --sans: 'MyCustomFont', system-ui, sans-serif;
  --transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Wrapper ── */
.ct-wrapper {
  max-width: 860px;
  margin: 0 auto;
  padding: 2.5rem 1.25rem 4rem;
  font-family: var(--sans);
  color: var(--text);
  min-height: 100vh;
}

/* ── Top bar ── */
.ct-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.ct-title h1 {
  font-size: 1.625rem;
  font-weight: 800;
  /* letter-spacing: -0.03em; */
  color: var(--secondary-color);
  line-height: 1.1;
}

.ct-title h1 span {
  color: var(--third-color);
}

.ct-sub {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 4px;
  font-family: var(--mono);
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* ── Stat pills ── */
.ct-stats {
  display: flex;
  gap: 8px;
}

.ct-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px;
  text-align: center;
  min-width: 76px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}

.ct-stat::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-dim), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}

.ct-stat:hover::before { opacity: 1; }
.ct-stat:hover { border-color: var(--border2); }

.ct-stat-val {
  display: block;
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text);
  font-family: var(--mono);
  line-height: 1.2;
  position: relative;
}

.ct-stat-lbl {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: gray;
  font-family: var(--mono);
  margin-top: 2px;
  position: relative;
}

/* ── Controls ── */
.ct-controls {
  display: flex;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  align-items: center;
}

.ct-control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ct-control-lbl {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-family: var(--mono);
  white-space: nowrap;
}

.ct-btn-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
}

.ct-btn-group button {
  font-size: 0.75rem;
  padding: 5px 12px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--mono);
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}

.ct-btn-group button:hover {
  background: var(--surface2);
  color: var(--text);
}

.ct-btn-group button.active {
  background: var(--secondary-color);
  color: #fff;
  /* box-shadow: 0 2px 8px var(--accent-glow); */
}

/* ── Card ── */
.ct-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 0.875rem;
  position: relative;
}

.ct-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.ct-card-dots {
  display: flex;
  gap: 5px;
  margin-right: 4px;
}

.ct-card-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border2);
}

.ct-card-dot:nth-child(1) { background: #f87171; }
.ct-card-dot:nth-child(2) { background: #fbbf24; }
.ct-card-dot:nth-child(3) { background: #34d399; }

.ct-lang-badge {
  font-size: 0.7rem;
  font-family: var(--mono);
  background: var(--accent-dim);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid rgba(124,106,255,0.2);
  font-weight: 600;
}

.ct-snippet-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  flex: 1;
  font-family: var(--mono);
}

.ct-progress-txt {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

/* ── Timer bar ── */
.ct-timer-bar-wrap {
  height: 2px;
  background: var(--border);
}

.ct-timer-bar {
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--green));
  width: 100%;
  transition: width 0.9s linear, background 1s;
}

.ct-timer-bar.warning {
  background: linear-gradient(90deg, var(--yellow), var(--red));
}

/* ── Code display ── */
.ct-code-scroll {
  max-height: 260px;
  overflow-y: auto;
  padding: 22px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
  font-family: var(--mono);
}

.ct-code-scroll::-webkit-scrollbar { width: 4px; }
.ct-code-scroll::-webkit-scrollbar-track { background: transparent; }
.ct-code-scroll::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.ct-code-display {
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 2;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Characters ── */
.ct-char { display: inline; }

.ct-char.done {
  color: var(--green);
}

.ct-char.wrong {
  color: var(--red);
  background: var(--red-dim);
  border-radius: 2px;
  outline: 1px solid rgba(248,113,113,0.3);
}

.ct-char.cursor {
  position: relative;
  color: var(--text);
}

.ct-char.cursor::before {
  content: '';
  position: absolute;
  left: -1px;
  top: 10%;
  bottom: 10%;
  width: 2px;
  background: var(--accent);
  border-radius: 2px;
  animation: blink 0.9s step-end infinite;
}

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

.ct-char.pending { 
  /* color: var(--text-muted);  */
  color: gray;
}

/* ── Progress bar ── */
.ct-progress-row { margin-bottom: 0.875rem; }

.ct-progress-wrap {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.ct-progress-fill {
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--green));
  border-radius: 2px;
  width: 0%;
  transition: width 0.12s ease-out;
}

/* ── Input shell + overlay ── */
.ct-input-shell {
  position: relative;
}

/* The textarea: transparent text, but keeps cursor & selection */
.ct-input {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.875rem;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: white;          /* hide raw text — overlay shows it coloured */
  caret-color: var(--accent);  /* cursor still visible */
  outline: none;
  min-height: 110px;
  line-height: 1.8;
  resize: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  position: relative;
  z-index: 2;                  /* above overlay so clicks/focus work */
}

.ct-input::placeholder { 
  /* color: var(--text-muted);  */
  color: gray;
}

.ct-input:focus {
  border-color: rgba(124,106,255,0.4);
  box-shadow: 0 0 0 3px var(--accent-dim), inset 0 1px 0 rgba(255,255,255,0.03);
}

.ct-input:disabled {
  background: var(--bg);
  cursor: not-allowed;
}

/* Overlay: sits behind textarea, perfectly aligned */
.ct-input-overlay {
  position: absolute;
  inset: 0;
  padding: 16px 18px;
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-all;
  pointer-events: none;        /* clicks pass through to textarea */
  z-index: 1;
  overflow: hidden;
  border-radius: var(--radius);
  color: var(--text);
}

/* Overlay character classes */
.ov-correct { color: var(--green); }
.ov-wrong   {
  color: var(--red);
  background: var(--red-dim);
  border-radius: 2px;
  outline: 1px solid rgba(248,113,113,.25);
}
.ov-extra   { color: var(--yellow); opacity: 0.7; }

/* Blinking caret in overlay (only shows when textarea has no native caret visible) */
.ov-caret {
  display: inline-block;
  width: 2px;
  height: 1.1em;
  background: var(--accent);
  vertical-align: text-bottom;
  border-radius: 1px;
  animation: blink 0.9s step-end infinite;
  opacity: 0; /* hidden — textarea's own caret is used instead */
}


.ct-input-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-family: var(--mono);
}

/* ── Actions ── */
.ct-actions {
  display: flex;
  gap: 8px;
  margin-top: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.ct-btn-new {
  padding: 9px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.8125rem;
  cursor: pointer;
  font-family: var(--mono);
  font-weight: 500;
  transition: all var(--transition);
}

.ct-btn-new:hover {
  background: var(--surface2);
  border-color: var(--border2);
  color: var(--text);
}

.ct-btn-submit {
  background: white;
  border-color: var(--secondary-color--hover);
  color: var(--secondary-color);
}

.ct-btn-submit:hover {
  background: var(--secondary-color);
  border-color: white;
  color: #fff;
}

/* ── Loading state ── */
.ct-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 24px;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.8rem;
}

.ct-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}


.cn-load-spinner {
    display: none;
    align-items: center;
    justify-content: center;
}

.cn-load-spinner.htmx-request{
  display: flex;
}

.cn-load-spinner.htmx-request + #code-display{
  opacity: 0;
}




@keyframes spin { to { transform: rotate(360deg); } }

/* ── HTMX request indicator ── */
/* .htmx-request .ct-loading { display: flex; } */
/* .htmx-request #code-display > *:not(.ct-loading) { opacity: 0.3; transition: opacity 0.2s; } */

/* ── Result card ── */
.ct-result {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 1rem;
  animation: slideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ct-result.show { display: block; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ct-result-header {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.ct-result-inner {
  padding: 2.5rem 2rem;
  text-align: center;
}

.ct-result-wpm {
  font-size: 4rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1;
  font-family: var(--mono);
  letter-spacing: -0.04em;
}

.ct-result-wpm span {
  font-size: 1.5rem;
  color: var(--accent);
  font-weight: 600;
}

.ct-result-wpm-lbl {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin: 6px 0 2rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.ct-result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 1.5rem;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.ct-result-stat {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  transition: border-color var(--transition);
}

.ct-result-stat:hover { border-color: var(--border2); }

.ct-result-stat-val {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  font-family: var(--mono);
}

.ct-result-stat-lbl {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: var(--mono);
}

.ct-result-msg {
  font-size: 0.875rem;
  color: var(--text-dim);
  margin-bottom: 1.5rem;
  font-family: var(--mono);
}

.ct-result-msg.great { color: var(--green); }
.ct-result-msg.good  { color: var(--yellow); }

.ct-result-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Accuracy ring (optional flair) ── */
.ct-acc-ring {
  display: inline-block;
  width: 60px; height: 60px;
  margin: 0 auto 1.5rem;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .ct-topbar { flex-direction: column; }
  .ct-stats { width: 100%; justify-content: space-between; }
  .ct-controls { gap: 1rem; }
  .ct-result-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .ct-result-wpm { font-size: 3rem; }
  .ct-code-scroll { max-height: 200px; }
}