/* ==========================================================================
   TermaType — Typing Tutor (Learn Typing)
   Full-page overlay with lesson categories, grapheme-cluster rendering,
   and WPM/accuracy tracking.

   Uses termaUI principles:
   - Grapheme clustering (prevents dotted-circle artifacts on combining marks)
   - OpenType ligatures (blws/abvs for correct consonant stacking)
   - Guardian padding (prevents Tibetan vowel mark clipping)
   - Anti-aliased font rendering
   ========================================================================== */

/* ── OVERLAY ───────────────────────────────────────────────────────────────── */
.tt-overlay {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: var(--c-bg, #F2EDE6);
  display: flex;
  flex-direction: column;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.98);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.tt-overlay.tt-visible {
  opacity: 1;
  pointer-events: all;
  transform: scale(1);
}

/* ── HEADER ────────────────────────────────────────────────────────────────── */
.tt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--c-titlebar, #1C1916);
  gap: 16px;
  flex-shrink: 0;
}

.tt-header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.tt-title {
  font-family: 'Jomolhari', 'Noto Serif Tibetan', 'Tibetan Machine Uni', serif;
  font-size: 16px;
  color: var(--c-accent-light, #E8A94B);
  line-height: 1.8;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.tt-subtitle {
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  font-weight: 500;
}

/* ── PILLS ─────────────────────────────────────────────────────────────────── */
.tt-pills {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: center;
}

.tt-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border: none;
  border-radius: 20px;
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.55);
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.tt-pill:hover {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.8);
}

.tt-pill.active {
  background: rgba(201,122,30,0.25);
  color: var(--c-accent-light, #E8A94B);
}

/* termaUI: Tibetan pill icons with proper font stack & ligatures */
.tt-pill-icon {
  font-family: 'Jomolhari', 'Noto Serif Tibetan', 'Tibetan Machine Uni', serif;
  font-size: 13px;
  line-height: 1.8;
  font-variant-ligatures: common-ligatures;
  font-feature-settings: "liga" 1, "blws" 1, "abvs" 1;
}

/* ── HEADER RIGHT ──────────────────────────────────────────────────────────── */
.tt-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tt-free-btn {
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.12);
  background: none;
  color: rgba(255,255,255,0.55);
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tt-free-btn:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.85);
  border-color: rgba(255,255,255,0.2);
}

.tt-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 6px;
  background: none;
  color: rgba(255,255,255,0.4);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.tt-close-btn:hover {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.9);
}

/* ── STATS BAR ─────────────────────────────────────────────────────────────── */
.tt-stats-bar {
  display: flex;
  justify-content: center;
  gap: 32px;
  padding: 14px 20px;
  background: var(--c-toolbar, #FAF7F3);
  border-bottom: 1px solid var(--c-border, #E0D9D0);
  flex-shrink: 0;
}

.tt-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tt-stat-val {
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--c-text, #1A1714);
  letter-spacing: -0.5px;
}

.tt-stat-label {
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 10px;
  font-weight: 500;
  color: var(--c-text-3, #8A837B);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── BODY ──────────────────────────────────────────────────────────────────── */
.tt-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  position: relative;
  overflow: hidden;
}

/* ── TYPING ZONE ───────────────────────────────────────────────────────────── */
.tt-zone {
  width: 100%;
  max-width: 720px;
  text-align: center;
}

/* termaUI: Full Tibetan font stack with ligatures, guard padding, anti-aliasing */
.tt-target {
  font-family: 'Jomolhari', 'Noto Serif Tibetan', 'Tibetan Machine Uni', serif;
  font-size: 36px;
  line-height: 2;
  color: var(--c-text-3, #8A837B);
  padding: 24px;
  padding-block: 0.5em;           /* tr-guard-lg: prevent vowel/stack clipping */
  min-height: 120px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 2px;
  user-select: none;

  /* termaUI: OpenType ligatures for correct Tibetan stacking */
  font-variant-ligatures: common-ligatures;
  font-feature-settings: "liga" 1, "blws" 1, "abvs" 1;

  /* termaUI: Anti-aliased rendering */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  /* termaUI: Tibetan text behavior */
  word-break: keep-all;
  overflow-wrap: anywhere;
}

/* ── GRAPHEME CLUSTER STATES ──────────────────────────────────────────────── */
/* Each .tc span contains a complete grapheme cluster (base + combining marks)
   so combining characters render correctly without dotted-circle artifacts. */
.tc {
  display: inline-block;
  position: relative;
  transition: color 0.1s ease;
  /* termaUI: guard padding for vowel marks that extend above/below */
  padding-block: 0.15em;
}

.tc.ok {
  color: #2D8A4E;
}

.tc.err {
  color: #C0392B;
  background: rgba(192, 57, 43, 0.08);
  border-radius: 3px;
}

.tc.cur {
  color: var(--c-accent, #C97A1E);
}

.tc.cur::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--c-accent, #C97A1E);
  border-radius: 2px;
  animation: cursor-pulse 1s ease-in-out infinite;
}

@keyframes cursor-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── HINT ──────────────────────────────────────────────────────────────────── */
.tt-hint {
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 13px;
  color: var(--c-text-3, #8A837B);
  margin-top: 20px;
  min-height: 24px;
}

.tt-hint kbd {
  font-family: var(--font-mono, 'SF Mono', Consolas, monospace);
  font-size: 12px;
  background: var(--c-statusbar, #EDEAE4);
  border: 1px solid var(--c-border, #E0D9D0);
  border-radius: 4px;
  padding: 2px 6px;
  margin: 0 2px;
}

/* termaUI: Hint character with proper Tibetan rendering */
.tt-hint-char {
  font-family: 'Jomolhari', 'Noto Serif Tibetan', 'Tibetan Machine Uni', serif;
  font-size: 18px;
  color: var(--c-accent, #C97A1E);
  vertical-align: middle;
  font-variant-ligatures: common-ligatures;
  font-feature-settings: "liga" 1, "blws" 1, "abvs" 1;
  -webkit-font-smoothing: antialiased;
}

/* ── HIDDEN INPUT ──────────────────────────────────────────────────────────── */
.tt-input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

/* ── FREE TYPE ZONE ────────────────────────────────────────────────────────── */
.tt-free-zone {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* termaUI: Free type textarea with Tibetan font stack and rendering */
.tt-free-input {
  width: 100%;
  height: 280px;
  padding: 24px;
  border: 1px solid var(--c-border, #E0D9D0);
  border-radius: 8px;
  background: var(--c-page, #FDFBF8);
  font-family: 'Jomolhari', 'Noto Serif Tibetan', 'Tibetan Machine Uni', serif;
  font-size: 22px;
  line-height: 2;
  color: var(--c-text, #1A1714);
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  /* termaUI rendering */
  font-variant-ligatures: common-ligatures;
  font-feature-settings: "liga" 1, "blws" 1, "abvs" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  word-break: keep-all;
}

.tt-free-input:focus {
  border-color: var(--c-accent, #C97A1E);
}

.tt-free-footer {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tt-free-count {
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 12px;
  color: var(--c-text-3, #8A837B);
  flex: 1;
}

.tt-free-action {
  padding: 5px 14px;
  border: 1px solid var(--c-border, #E0D9D0);
  border-radius: 6px;
  background: var(--c-toolbar, #FAF7F3);
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 12px;
  font-weight: 500;
  color: var(--c-text-2, #4A4540);
  cursor: pointer;
  transition: background 0.12s;
}

.tt-free-action:hover {
  background: var(--c-bg, #F2EDE6);
}

/* ── RESULT OVERLAY ────────────────────────────────────────────────────────── */
.tt-result {
  position: absolute;
  inset: 0;
  background: rgba(28,25,22,0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.tt-result-card {
  background: var(--c-page, #FDFBF8);
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.2);
  max-width: 400px;
}

.tt-result-emoji {
  font-size: 40px;
  margin-bottom: 12px;
}

.tt-result-title {
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 20px;
  font-weight: 700;
  color: var(--c-text, #1A1714);
  margin-bottom: 8px;
}

.tt-result-detail {
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 13px;
  color: var(--c-text-3, #8A837B);
  margin-bottom: 24px;
}

.tt-result-btn {
  padding: 10px 28px;
  border: none;
  border-radius: 8px;
  background: var(--c-accent, #C97A1E);
  color: white;
  font-family: var(--font-ui, Inter, sans-serif);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.tt-result-btn:hover {
  background: var(--c-accent-dark, #A36418);
}

/* ── RESPONSIVE ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .tt-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px;
  }
  .tt-pills { order: 3; width: 100%; justify-content: flex-start; }
  .tt-target { font-size: 28px; padding: 16px; }
  .tt-stats-bar { gap: 20px; padding: 10px 14px; }
  .tt-stat-val { font-size: 16px; }
  .tt-body { padding: 24px 14px; }
}

@media (max-width: 480px) {
  .tt-target { font-size: 22px; }
  .tt-pill { padding: 4px 10px; font-size: 11px; }
  .tt-result-card { padding: 28px 24px; }
}

/* ── Hide everything else when tutor is active ─────────────────────────────── */
body.tutor-active #app {
  visibility: hidden;
}

/* Keep on-screen keyboard visible above tutor overlay */
body.tutor-active .kb-container {
  z-index: 850;
}
