/* ==========================================================
   All Keyboards – Typing Tutor page
   (header, footer and the on-screen keyboard come from style.css)
   ========================================================== */
.tt-page {
  --tt-ink: #10262c;
  --tt-muted: #5b6b70;
  --tt-line: #e2e9eb;
  --tt-soft: #e3f1f4;
  --tt-surface: #f8fbfb;    /* stat strips, text boxes */
  --tt-ok: #1b8a7a;
  --tt-bad: #d64545;
  --tt-radius: 16px;
  --tt-shadow: 0 1px 2px rgba(16, 38, 44, .04), 0 8px 24px rgba(16, 38, 44, .05);
  --tt-script: var(--font-hi);

  font-family: "Plus Jakarta Sans", var(--font-hi), system-ui, sans-serif;
  color: var(--tt-ink);
  background: #f3f7f8;
  padding: 44px 0 72px;
}
.tt-page svg.lucide { width: 18px; height: 18px; stroke-width: 1.8; flex-shrink: 0; }
.tt-muted { color: var(--tt-muted); }

/* ---------- Hero ---------- */
.tt-hero { max-width: 720px; margin-bottom: 28px; }
.tt-eyebrow { margin: 0 0 10px; font-size: .78rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--teal-dark); }
.tt-title { margin: 0 0 10px; font-size: clamp(1.35rem, 2vw, 1.6rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.tt-lead { margin: 0; font-size: .875rem; line-height: 1.6; color: var(--tt-muted); }

/* ---------- Tabs + settings ---------- */
.tt-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding: 8px;
  background: var(--white);
  border: 1px solid var(--tt-line);
  border-radius: 14px;
  box-shadow: var(--tt-shadow);
}
.tt-tabs { display: inline-flex; gap: 4px; padding: 4px; border-radius: 11px; background: #eef4f5; }
.tt-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #33454a;
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  transition: background .15s, color .15s, box-shadow .15s;
}
.tt-tab:hover { color: var(--tt-ink); }
.tt-tab.is-active { background: var(--white); color: var(--teal-dark); box-shadow: 0 1px 3px rgba(16, 38, 44, .12); }
.tt-tab:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

.tt-settings { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding-right: 4px; }
.tt-field { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: .82rem; font-weight: 600; color: var(--tt-muted); }
.tt-field[hidden] { display: none; }
.tt-select {
  appearance: none;
  min-width: 120px;
  padding: 8px 34px 8px 12px;
  border: 1px solid #d5dfe2;
  border-radius: 9px;
  background: var(--white) url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235b6b70' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='m6 9 6 6 6-6'/%3e%3c/svg%3e") no-repeat right 10px center / 16px;
  color: var(--tt-ink);
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
}
.tt-select:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(63, 167, 191, .18); }
.tt-select:disabled { opacity: .55; cursor: not-allowed; }

.tt-note {
  margin: -8px 0 24px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--tt-soft);
  color: var(--teal-dark);
  font-size: .9rem;
}

/* ---------- Cards & buttons ---------- */
.tt-card { background: var(--white); border: 1px solid var(--tt-line); border-radius: var(--tt-radius); box-shadow: var(--tt-shadow); }

.tt-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: 10px;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.tt-btn:active { transform: translateY(1px); }
.tt-btn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }
.tt-btn--primary { border: 0; background: var(--teal-dark); color: var(--white); }
.tt-btn--primary:hover { background: #0f4f5d; }
.tt-btn--primary:disabled { background: #9fb4b9; cursor: not-allowed; }
.tt-btn--ghost { border: 1px solid #d5dfe2; background: var(--white); color: var(--tt-ink); }
.tt-btn--ghost:hover { border-color: var(--teal); color: var(--teal-dark); }

/* card heading: small level label + title, action on the right */
.tt-practice-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.tt-level { margin: 0 0 4px; font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--teal-dark); }
.tt-practice-head h2 { margin: 0; font-size: 1.3rem; font-weight: 700; letter-spacing: -.01em; }

/* ---------- Live stats strip (lessons + speed test) ---------- */
.tt-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.6fr);
  margin-bottom: 20px;
  border: 1px solid var(--tt-line);
  border-radius: 12px;
  background: var(--tt-surface);
  overflow: hidden;
}
#panel-test .tt-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tt-stat { padding: 12px 18px; min-width: 0; }
.tt-stat + .tt-stat { border-left: 1px solid var(--tt-line); }
.tt-stat-label { display: block; font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tt-muted); }
.tt-stat-value { display: block; margin-top: 2px; font-size: 1.45rem; font-weight: 800; line-height: 1.25; font-variant-numeric: tabular-nums; }
.tt-stat--progress { display: flex; flex-direction: column; justify-content: center; }
.tt-stat--time .tt-stat-value { color: var(--teal-dark); }
.tt-stat--time.is-low { background: #fdf0f0; }
.tt-stat--time.is-low .tt-stat-value { color: var(--tt-bad); }

.tt-bar { display: block; height: 8px; margin-top: 12px; border-radius: 999px; background: #e3ecee; overflow: hidden; }
.tt-bar-fill { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--teal-dark)); transition: width .2s; }

/* ---------- Lessons ---------- */
.tt-lessons { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 24px; align-items: stretch; }

/* the practice card sets the row height; the list scrolls inside it */
.tt-lesson-list { contain: size; display: flex; flex-direction: column; overflow: hidden; }
.tt-list-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--tt-line); }
.tt-list-head h2 { margin: 0; font-size: 1rem; font-weight: 700; }
.tt-list-progress { padding: 3px 10px; border-radius: 999px; background: var(--tt-soft); color: var(--teal-dark); font-size: .76rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.tt-list-body { padding: 6px 10px 14px; overflow-y: auto; scrollbar-width: thin; }
.tt-list-body > .tt-muted { margin: 12px 10px; font-size: .9rem; }

.tt-group-title { margin: 14px 10px 6px; font-size: .68rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #8a989c; }
.tt-lesson {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  align-items: start;
  gap: 12px;
  width: 100%;
  margin-bottom: 2px;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--tt-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .15s;
}
.tt-lesson:hover:not(:disabled) { background: #f1f6f7; }
.tt-lesson.is-selected { background: var(--tt-soft); box-shadow: inset 3px 0 0 var(--teal-dark); }
.tt-lesson:disabled { cursor: not-allowed; }
.tt-lesson:disabled .tt-lesson-name { color: #7d8b8f; }
.tt-lesson:focus-visible { outline: 2px solid var(--teal); outline-offset: -2px; }
.tt-lesson-icon { display: grid; place-items: center; width: 26px; height: 26px; margin-top: 1px; border-radius: 50%; background: #eef3f4; color: #8a989c; }
.tt-page .tt-lesson-icon svg.lucide { width: 13px; height: 13px; stroke-width: 2.2; }
.tt-lesson[data-status="completed"] .tt-lesson-icon { background: var(--tt-ok); color: var(--white); }
.tt-lesson[data-status="in_progress"] .tt-lesson-icon { background: var(--teal-dark); color: var(--white); }
.tt-lesson-body { display: block; min-width: 0; }
.tt-lesson-name { display: flex; gap: 6px; font-size: .88rem; font-weight: 600; line-height: 1.45; }
.tt-lesson-no { flex-shrink: 0; color: var(--tt-muted); font-variant-numeric: tabular-nums; }
.tt-lesson-title { min-width: 0; overflow-wrap: anywhere; }
.tt-lesson-keys { display: block; margin-top: 1px; font-family: var(--tt-script); font-size: .86rem; line-height: 1.5; color: var(--teal-dark); word-spacing: .15em; overflow-wrap: anywhere; }
.tt-lesson:disabled .tt-lesson-keys { color: #8a989c; }
.tt-lesson-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 3px; }
.tt-lesson-meta { font-size: .74rem; font-weight: 500; color: var(--tt-muted); }
.tt-lesson-stars { font-size: .74rem; letter-spacing: 1px; color: #f2b01e; white-space: nowrap; }
.tt-lesson-stars .off { color: #d9e1e3; }

/* practice card */
.tt-practice { position: relative; padding: 24px 28px 28px; min-width: 0; }

.tt-target-wrap { position: relative; }
.tt-target {
  min-height: 168px;
  padding: 22px 26px 66px; /* room for the start hint */
  border: 1px solid var(--tt-line);
  border-radius: 12px;
  background: var(--tt-surface);
  font-family: var(--tt-script);
  font-size: 1.85rem;
  line-height: 2.05;
  word-spacing: .12em;
  cursor: text;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.tt-target-wrap.is-focused .tt-target { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(63, 167, 191, .14); background: var(--white); }
.tt-target.is-latin { font-family: "Plus Jakarta Sans", system-ui, sans-serif; font-size: 1.6rem; letter-spacing: .02em; }

/* one span per letter (grapheme) */
.tt-ch { position: relative; color: #9aa9ad; transition: color .1s; }
.tt-ch.is-ok { color: var(--tt-ok); }
.tt-ch.is-bad { color: var(--tt-bad); text-decoration: underline 2px; text-underline-offset: 8px; }
.tt-ch.is-current { color: var(--tt-ink); background: rgba(63, 167, 191, .16); border-radius: 4px; }
.tt-ch.is-current::before {
  content: "";
  position: absolute;
  left: -2px;
  top: 18%;
  width: 2px;
  height: 64%;
  background: var(--teal-dark);
  animation: tt-blink 1s steps(1) infinite;
}
@keyframes tt-blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .tt-ch.is-current::before { animation: none; } }

.tt-start-hint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 0;
  border-radius: 999px;
  background: var(--teal-dark);
  color: var(--white);
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(19, 94, 110, .22);
  cursor: pointer;
}
.tt-page .tt-start-hint svg.lucide { width: 16px; height: 16px; }
.tt-target-wrap.is-focused .tt-start-hint { display: none; }

/* off-screen input that receives the keys */
.tt-capture {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  resize: none;
  pointer-events: none;
}

/* keyboard guide – part of the practice card */
.tt-keyboard { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--tt-line); }
.tt-keyboard-hint { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; font-size: .8rem; color: var(--tt-muted); }
.tt-key-swatch { width: 14px; height: 14px; border: 1.5px solid var(--teal-dark); border-radius: 4px; background: #dceef0; box-shadow: 0 0 0 2px rgba(63, 167, 191, .45); }
.tt-keyboard .vkeyboard {
  --key-h: 46px;
  --gap: 6px;
  max-width: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-family: var(--font);
}
.tt-keyboard .key { cursor: default; border-color: #d8dfe1; }
.tt-keyboard .key:hover { border-color: #d8dfe1; }
.tt-keyboard .key.is-next { border-color: var(--teal-dark); background: #dceef0; box-shadow: 0 0 0 2px var(--teal); }
.tt-keyboard .key--mod.is-next { background: var(--teal-dark); }
.tt-keyboard .key.is-wrong { border-color: var(--tt-bad) !important; background: #fde8e8 !important; animation: tt-shake .25s; }
@keyframes tt-shake { 25% { transform: translateX(-2px); } 75% { transform: translateX(2px); } }
.tt-keyboard .glyph.is-mark { font-family: var(--font-marks, var(--font-hi)); }

/* lesson result – covers the practice card */
.tt-result {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  border-radius: var(--tt-radius);
  background: rgba(255, 255, 255, .97);
  text-align: center;
  animation: tt-fade .2s ease-out;
}
.tt-result[hidden] { display: none; }
@keyframes tt-fade { from { opacity: 0; transform: scale(.98); } }
.tt-stars { margin-bottom: 8px; font-size: 2.4rem; letter-spacing: 6px; color: #f2b01e; }
.tt-stars .off { color: #dfe6e8; }
.tt-result h3 { margin: 0 0 6px; font-size: 1.4rem; font-weight: 800; }
.tt-result p { margin: 0 0 20px; max-width: 420px; }
.tt-result-stats { display: grid; grid-template-columns: repeat(4, minmax(96px, 1fr)); gap: 10px; margin: 0 0 22px; }
.tt-result-stats div, .tt-result-grid div { padding: 12px 16px; border: 1px solid var(--tt-line); border-radius: 12px; background: var(--tt-surface); }
.tt-result-stats dt, .tt-result-grid dt { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--tt-muted); }
.tt-result-stats dd, .tt-result-grid dd { margin: 2px 0 0; font-size: 1.4rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.tt-result-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- Speed test ---------- */
.tt-test { padding: 24px 28px 28px; }
.tt-passage {
  max-height: 260px;
  overflow-y: auto;
  padding: 20px 24px;
  border: 1px solid var(--tt-line);
  border-radius: 12px;
  background: var(--tt-surface);
  font-family: var(--tt-script);
  font-size: 1.3rem;
  line-height: 2;
  user-select: none;
  -webkit-user-select: none;
}
.tt-passage.is-latin { font-family: "Plus Jakarta Sans", system-ui, sans-serif; font-size: 1.15rem; }
.tt-input-label { display: block; margin: 20px 0 8px; font-size: .84rem; font-weight: 600; color: var(--tt-muted); }
.tt-input {
  display: block;
  width: 100%;
  padding: 14px 18px;
  border: 1px solid #d5dfe2;
  border-radius: 12px;
  font-family: var(--tt-script);
  font-size: 1.2rem;
  line-height: 1.7;
  resize: vertical;
}
.tt-input.is-latin { font-family: "Plus Jakarta Sans", system-ui, sans-serif; font-size: 1.05rem; }
.tt-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 4px rgba(63, 167, 191, .14); }
.tt-input[readonly] { background: #f3f6f7; color: var(--tt-muted); }

.tt-test-result { margin-top: 24px; padding: 24px 28px 28px; animation: tt-fade .2s ease-out; }
.tt-test-result[hidden] { display: none; }
.tt-test-result-head { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.tt-test-result-head h3 { margin: 0 0 2px; font-size: 1.25rem; font-weight: 800; }
.tt-test-result-head p { margin: 0; }
.tt-trophy { display: grid; place-items: center; width: 46px; height: 46px; border-radius: 12px; background: var(--tt-soft); color: var(--teal-dark); }
.tt-page .tt-trophy svg.lucide { width: 22px; height: 22px; }
.tt-result-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; margin: 0 0 14px; }
.tt-result-grid .is-main { border-color: var(--teal-dark); background: var(--teal-dark); color: var(--white); }
.tt-result-grid .is-main dt { color: rgba(255, 255, 255, .75); }
.tt-formula { margin: 0 0 20px; font-size: .78rem; color: var(--tt-muted); }
.tt-test-result .tt-result-actions { justify-content: flex-start; }

/* ---------- History ---------- */
.tt-history { margin-top: 24px; padding: 24px 28px 28px; }
.tt-history-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.tt-history-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; background: var(--tt-soft); color: var(--teal-dark); }
.tt-history-head h2 { margin: 0 0 2px; font-size: 1.1rem; font-weight: 700; }
.tt-history-head p { margin: 0; font-size: .85rem; }
.tt-chart-wrap { position: relative; height: 280px; }
.tt-chart-wrap:has(> .tt-chart-empty:not([hidden])) { height: 112px; } /* no results yet: keep the card compact */
.tt-chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 16px;
  border: 1px dashed #d5dfe2;
  border-radius: 12px;
  background: var(--tt-surface);
  color: var(--tt-muted);
  font-size: .9rem;
  text-align: center;
}
.tt-chart-empty[hidden] { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 991.98px) {
  .tt-lessons { grid-template-columns: 1fr; }
  .tt-lesson-list { contain: none; max-height: 340px; }
  .tt-result-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 767.98px) {
  .tt-page { padding: 28px 0 56px; }
  .tt-lead { font-size: .85rem; }
  .tt-controls { flex-direction: column; align-items: stretch; }
  .tt-tabs { display: grid; grid-template-columns: 1fr 1fr; }
  .tt-tab { justify-content: center; }
  .tt-settings { display: grid; grid-template-columns: 1fr 1fr; padding: 0 4px 4px; }
  .tt-field { flex-direction: column; align-items: stretch; gap: 4px; }
  .tt-select { min-width: 0; }
  .tt-practice, .tt-test, .tt-history, .tt-test-result { padding: 18px; }
  .tt-practice-head { align-items: flex-start; }
  .tt-practice-head h2 { font-size: 1.1rem; }
  .tt-stats, #panel-test .tt-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tt-stat:nth-child(3) { border-left: 0; }
  .tt-stat:nth-child(n + 3) { border-top: 1px solid var(--tt-line); }
  .tt-stat { padding: 10px 14px; }
  .tt-stat-value { font-size: 1.25rem; }
  .tt-target { font-size: 1.5rem; padding: 16px 16px 60px; }
  .tt-result-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tt-result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tt-keyboard { display: none; } /* phones type with their own keyboard */
}
