/* ==============================================================
   TRANSLATION PRACTICE (LUYỆN TẬP DỊCH TIẾNG)
   Siêu mượt, không giật lag, tối ưu GPU 60fps trên điện thoại & PC
   ============================================================== */

#translation-mode {
  display: none;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
  box-sizing: border-box;
  animation: trFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  contain: content;
  transform: translateZ(0);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#translation-mode.active {
  display: block;
}

@keyframes trFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header & Level Selector */
.tr-header {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.9));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 18px 20px;
  margin-bottom: 18px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.tr-title-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.tr-title-wrap h2 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 10px;
  background: linear-gradient(135deg, #38bdf8, #818cf8, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.tr-stats-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 12px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #38bdf8;
}

/* HSK Level Tabs */
.tr-level-tabs {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

@media (max-width: 640px) {
  .tr-level-tabs {
    grid-template-columns: repeat(3, 1fr);
  }
}

.tr-level-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px 4px;
  color: #cbd5e1;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  text-align: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tr-level-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  transform: translateY(-1px);
}

.tr-level-btn.active {
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  border-color: #60a5fa;
  color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
  transform: translateY(-1px);
}

/* Mode & Filter Bar */
.tr-mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.tr-mode-buttons {
  display: flex;
  gap: 6px;
  background: rgba(0, 0, 0, 0.3);
  padding: 4px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-wrap: wrap;
}

.tr-mode-btn {
  background: transparent;
  border: none;
  color: #94a3b8;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  touch-action: manipulation;
}

.tr-mode-btn.active {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.tr-topic-filter {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  padding: 7px 12px;
  color: #e2e8f0;
  font-size: 0.82rem;
  outline: none;
  max-width: 240px;
  cursor: pointer;
}

/* Practice Card */
.tr-practice-card {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.75), rgba(15, 23, 42, 0.85));
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  padding: 22px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  margin-bottom: 20px;
  position: relative;
  overflow: hidden;
  transform: translateZ(0);
}

.tr-card-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.tr-progress-info {
  font-size: 0.84rem;
  font-weight: 700;
  color: #94a3b8;
}

.tr-progress-meter {
  flex: 1;
  max-width: 180px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
  margin: 0 12px;
}

.tr-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.tr-streak-badge {
  display: none !important;
}

/* Grammar structure pill */
.tr-structure-pill {
  display: inline-flex;
  align-items: center;
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 14px;
}

/* Prompt Box */
.tr-prompt-box {
  margin-bottom: 18px;
}

.tr-prompt-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: #94a3b8;
  margin-bottom: 8px;
}

.tr-prompt-text {
  font-size: 1.35rem;
  font-weight: 700;
  color: #f8fafc;
  line-height: 1.45;
  margin: 0;
}

.tr-zh-display {
  font-size: 1.85rem;
  font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
  font-weight: 700;
  color: #f8fafc;
  margin-bottom: 6px;
  line-height: 1.35;
}

.tr-pinyin-display {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1.05rem;
  color: #38bdf8;
  font-weight: 600;
  margin-bottom: 10px;
}

/* Audio button */
.tr-audio-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #38bdf8;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
  touch-action: manipulation;
}

.tr-audio-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  transform: scale(1.05);
}

/* Active playing state with subtle breathing pulse */
.tr-audio-btn.playing {
  background: rgba(56, 189, 248, 0.35);
  border-color: #38bdf8;
  animation: tr-pulse-audio 1s ease-in-out infinite alternate;
}

@keyframes tr-pulse-audio {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.4); }
  100% { transform: scale(1.12); box-shadow: 0 0 10px 2px rgba(56, 189, 248, 0.3); }
}

/* Input Area */
.tr-input-area {
  margin-bottom: 18px;
}

.tr-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.tr-text-input {
  width: 100%;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: rgba(15, 23, 42, 0.7);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 13px 44px 13px 16px;
  color: #fff;
  font-size: 1.15rem;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.tr-text-input:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.15);
  background: rgba(15, 23, 42, 0.9);
}

.tr-clear-btn {
  position: absolute;
  right: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #94a3b8;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.tr-clear-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

/* Word bank chips */
.tr-word-bank-header {
  font-size: 0.78rem;
  font-weight: 700;
  color: #64748b;
  margin-top: 12px;
  margin-bottom: 6px;
}

.tr-word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 12px;
  min-height: 48px;
}

.tr-word-chip {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 7px 13px;
  color: #f1f5f9;
  font-size: 0.96rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: transform 0.12s ease, opacity 0.12s ease;
  touch-action: manipulation;
}

.tr-word-chip:hover {
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}

.tr-word-chip.used {
  opacity: 0.3;
  pointer-events: none;
}

/* Celebratory & Retry Feedback Box */
.tr-feedback-box {
  display: none;
  padding: 16px 20px;
  border-radius: 16px;
  margin-bottom: 16px;
  animation: trBounceIn 0.28s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-sizing: border-box;
}

@keyframes trBounceIn {
  0% { opacity: 0; transform: scale(0.96) translateY(5px); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.tr-feedback-content {
  display: flex;
  align-items: center;
  gap: 14px;
}

.tr-feedback-icon {
  font-size: 2rem;
  line-height: 1;
  flex-shrink: 0;
}

.tr-feedback-texts {
  flex: 1;
}

.tr-feedback-title {
  display: block;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.2px;
  margin-bottom: 3px;
}

.tr-feedback-sub {
  margin: 0;
  font-size: 0.88rem;
  opacity: 0.95;
  line-height: 1.4;
}

.tr-feedback-box.correct {
  display: block;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.18), rgba(5, 150, 105, 0.26));
  border: 1.5px solid rgba(16, 185, 129, 0.55);
  color: #34d399;
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.25);
}

.tr-feedback-box.correct .tr-feedback-title {
  color: #6ee7b7;
}

.tr-feedback-box.correct .tr-feedback-sub {
  color: #a7f3d0;
}

.tr-feedback-box.incorrect {
  display: block;
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.16), rgba(220, 38, 38, 0.24));
  border: 1.5px solid rgba(239, 68, 68, 0.45);
  color: #f87171;
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.2);
}

.tr-feedback-box.incorrect .tr-feedback-title {
  color: #fca5a5;
}

.tr-feedback-box.incorrect .tr-feedback-sub {
  color: #fecaca;
}

/* Action Buttons */
.tr-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  width: 100%;
}

.tr-btn-primary, .tr-btn-success, .tr-btn-secondary, .tr-btn-ghost {
  flex: 1;
  border-radius: 14px;
  padding: 14px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  touch-action: manipulation;
  user-select: none;
  border: none;
}

.tr-btn-primary {
  background: linear-gradient(135deg, #3b82f6, #4f46e5);
  color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.tr-btn-primary:hover {
  background: linear-gradient(135deg, #2563eb, #4338ca);
  transform: translateY(-1px);
}

.tr-btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.35);
}

.tr-btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-1px);
}

.tr-btn-secondary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3);
}

.tr-btn-secondary:hover {
  background: linear-gradient(135deg, #d97706, #b45309);
  transform: translateY(-1px);
}

.tr-btn-ghost {
  flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.08);
  color: #cbd5e1;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.tr-btn-ghost:hover {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
}

/* Summary View */
.tr-summary-view {
  display: none;
  text-align: center;
  padding: 28px 20px;
}

.tr-summary-view.active {
  display: block;
}

.tr-summary-trophy {
  font-size: 3.2rem;
  margin-bottom: 10px;
}

.tr-summary-title {
  font-size: 1.55rem;
  font-weight: 800;
  margin-bottom: 6px;
  color: #f8fafc;
}

.tr-summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 440px;
  margin: 18px auto;
}

.tr-stat-box {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  padding: 12px;
}

.tr-stat-box b {
  display: block;
  font-size: 1.45rem;
  color: #38bdf8;
  margin-bottom: 4px;
}

.tr-stat-box span {
  font-size: 0.78rem;
  color: #94a3b8;
  font-weight: 600;
}

.tr-summary-actions {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

/* Mobile Friendly Optimization */
@media (max-width: 600px) {
  #translation-mode {
    padding: 10px;
  }
  .tr-header {
    padding: 14px;
  }
  .tr-practice-card {
    padding: 16px;
  }
  .tr-prompt-text {
    font-size: 1.15rem;
  }
  .tr-zh-display {
    font-size: 1.5rem;
  }
  .tr-mode-buttons {
    width: 100%;
  }
  .tr-mode-btn {
    flex: 1;
    text-align: center;
    font-size: 0.8rem;
    padding: 8px 6px;
  }
  .tr-topic-filter {
    width: 100%;
    max-width: 100%;
  }
}
