/* ==================== CSS Variables ==================== */
:root {
  --bg-primary: #0d0d1a;
  --bg-secondary: #13132a;
  --bg-card: #1a1a35;
  --bg-card-hover: #22224a;
  --bg-input: #1e1e3a;
  --bg-input-focus: #25254a;
  --accent: #7c6cf0;
  --accent-hover: #9589f5;
  --accent-dim: rgba(124, 108, 240, 0.12);
  --accent-glow: rgba(124, 108, 240, 0.4);
  --success: #00c48c;
  --success-dim: rgba(0, 196, 140, 0.15);
  --error: #ff4757;
  --error-dim: rgba(255, 71, 87, 0.15);
  --warning: #ffa502;
  --text-primary: #eeeef5;
  --text-secondary: #9090b0;
  --text-dim: #555575;
  --border: #2a2a50;
  --border-light: #35355a;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 4px 32px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.3);
  --transition: 0.2s ease;
  --font-sans: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

::selection {
  background: var(--accent-dim);
  color: var(--accent);
}

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ==================== Header ==================== */
#main-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 32px;
  background: rgba(13, 13, 26, 0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

#fireworks-canvas {
  position: fixed;
  inset: 0;
  z-index: 250;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

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

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.tagline {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.header-nav {
  display: flex;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.nav-btn:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.nav-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

/* ==================== Views ==================== */
.view {
  display: none;
  animation: fadeIn 0.3s ease;
}

.view.active {
  display: block;
}

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

.view-container {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px;
}

/* ==================== Library ==================== */
.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.library-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

.library-actions {
  display: flex;
  gap: 8px;
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.course-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  transition: all var(--transition);
  cursor: default;
}

.course-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.course-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.course-card-title {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.4;
}

.course-card-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.course-card:hover .course-card-actions {
  opacity: 1;
}

.course-card-meta {
  display: flex;
  gap: 16px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.course-card-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.course-card-footer {
  display: flex;
  gap: 8px;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-sm {
  padding: 7px 14px;
  font-size: 0.85rem;
}

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-input-focus);
  border-color: var(--border-light);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--error-dim);
  color: var(--error);
  border: 1px solid rgba(255, 71, 87, 0.2);
}
.btn-danger:hover {
  background: rgba(255, 71, 87, 0.25);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.btn-icon-sm {
  width: 28px;
  height: 28px;
}

/* ==================== Form Elements ==================== */
.form-group {
  margin-bottom: 20px;
}

.form-group > label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.text-input, .textarea-input, .select-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: all var(--transition);
  outline: none;
}

.text-input:focus, .textarea-input:focus, .select-input:focus {
  border-color: var(--accent);
  background: var(--bg-input-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.textarea-input {
  resize: vertical;
  min-height: 100px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.6;
}

.select-input {
  cursor: pointer;
}

.select-input option {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Range input */
.range-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.range-input {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  outline: none;
}

.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
}

.range-value {
  min-width: 40px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--accent);
}

/* Toggle */
.toggle {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 13px;
  transition: all var(--transition);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: all var(--transition);
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(22px);
}

/* ==================== Settings ==================== */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.setting-group {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.setting-group:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.setting-group:first-child {
  padding-top: 0;
}

.setting-label {
  font-weight: 600;
  font-size: 0.95rem;
  flex-basis: 100%;
}

.setting-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
  flex: 1;
}

.kokoro-settings-group.hidden {
  display: none;
}

.kokoro-subrow {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.kokoro-mirror-wrap {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kokoro-sublabel {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.kokoro-actions {
  display: flex;
  gap: 8px;
}

.kokoro-status-panel {
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kokoro-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
}

.kokoro-status-text {
  color: var(--text-secondary);
}

.kokoro-status-text.ready {
  color: var(--success);
}

.kokoro-status-text.error {
  color: var(--error);
}

.kokoro-progress-pct {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
}

.kokoro-status-panel .progress-bar.hidden {
  display: none;
}

/* ==================== Practice View ==================== */
#practice-view {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-primary);
  overflow-y: auto;
}

.practice-container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 24px 28px;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(185px, 235px) minmax(0, 760px) minmax(185px, 235px);
  justify-content: center;
  align-items: stretch;
  gap: clamp(16px, 2.5vw, 36px);
}

.practice-side {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.practice-side-right {
  justify-content: center;
}

.side-panels {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.practice-side-left .side-panels {
  margin: auto 0;
}

.side-card {
  background: rgba(26, 26, 53, 0.72);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-card-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.practice-center {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 12px 0;
}

/* Practice top bar */
.practice-top-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.practice-info {
  flex: 1;
  min-width: 0;
  text-align: left;
}

.course-title-text {
  display: block;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.practice-stats {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.kb-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.kb-toggle-btn:hover {
  background: var(--bg-input-focus);
  border-color: var(--border-light);
  color: var(--text-primary);
}

.kb-toggle-btn.active {
  color: var(--text-primary);
  background: var(--accent-dim);
  border-color: rgba(124, 108, 240, 0.35);
}

.kb-toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.kb-toggle-pill {
  position: relative;
  width: 30px;
  height: 16px;
  border-radius: 999px;
  background: var(--border);
  flex-shrink: 0;
  transition: background var(--transition);
}

.kb-toggle-pill::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-primary);
  transition: transform var(--transition);
}

.kb-toggle-btn.active .kb-toggle-pill {
  background: var(--accent);
}

.kb-toggle-btn.active .kb-toggle-pill::after {
  transform: translateX(14px);
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.stat-value {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stat-label {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  color: var(--text-dim);
}

#practice-score {
  color: var(--warning);
  font-weight: 600;
}

/* Progress */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: 3px;
  transition: width 0.4s ease;
  width: 0%;
}

.progress-text {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Sentence counter */
.sentence-counter {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Combo toast */
.combo-toast {
  position: fixed;
  top: 32px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: var(--radius);
  box-shadow: 0 0 30px var(--accent-glow);
  z-index: 300;
  animation: comboIn 0.4s ease;
  pointer-events: none;
}

.combo-toast.hidden {
  display: none;
}

@keyframes comboIn {
  0% { opacity: 0; transform: translateX(-50%) scale(0.6) translateY(20px); }
  60% { opacity: 1; transform: translateX(-50%) scale(1.1) translateY(-5px); }
  100% { transform: translateX(-50%) scale(1) translateY(0); }
}

/* Chinese hint */
.chinese-hint {
  width: 100%;
  text-align: center;
  font-size: 1.25rem;
  color: var(--text-secondary);
  padding: 12px 20px;
  background: var(--accent-dim);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(124, 108, 240, 0.1);
}

.chinese-hint.hidden {
  display: none;
}

/* Answer card */
.answer-card {
  width: 100%;
  text-align: center;
  padding: 16px 24px;
  background: var(--success-dim);
  border: 1px solid rgba(0, 196, 140, 0.2);
  border-radius: var(--radius-sm);
  animation: slideDown 0.3s ease;
}

.answer-card.hidden {
  display: none;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.answer-en {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 6px;
  font-family: var(--font-mono);
}

.answer-zh {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

/* Word input area */
.word-input-area {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px 14px;
  padding: 24px 0;
  min-height: 140px;
}

.word-slot {
  position: relative;
  display: inline-grid;
  align-items: center;
}

.word-slot input,
.word-slot .word-width {
  grid-area: 1 / 1;
  min-width: 3ch;
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 500;
  padding: 6px 4px;
  letter-spacing: 0.5px;
}

.word-slot .word-width {
  visibility: hidden;
  white-space: pre;
  border-bottom: 3px solid transparent;
  padding-right: 10px;
}

.word-slot input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  border: none;
  border-bottom: 3px solid var(--text-dim);
  color: var(--text-primary);
  text-align: center;
  outline: none;
  transition: border-color var(--transition), color var(--transition);
}

.word-slot input::placeholder {
  color: transparent;
}

.word-slot.active input {
  border-bottom-color: var(--accent);
}

.word-slot.correct input {
  color: var(--success);
  border-bottom-color: var(--success);
}

.word-input-area.success .word-slot {
  animation: correctBurst 0.65s cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--slot-index, 0) * 45ms);
}

.word-input-area.success .word-slot::after {
  content: '✦';
  position: absolute;
  top: -0.8rem;
  right: -0.25rem;
  color: #facc15;
  font-size: 1rem;
  text-shadow: 0 0 12px rgba(250, 204, 21, 0.9);
  pointer-events: none;
  animation: correctSparkle 0.7s ease-out both;
  animation-delay: calc(var(--slot-index, 0) * 45ms + 100ms);
}

@keyframes correctBurst {
  0% { opacity: 0.55; transform: translateY(14px) scale(0.78); }
  58% { opacity: 1; transform: translateY(-5px) scale(1.14); }
  78% { transform: translateY(2px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes correctSparkle {
  0% { opacity: 0; transform: translateY(8px) scale(0.2) rotate(-35deg); }
  45% { opacity: 1; transform: translateY(-7px) scale(1.35) rotate(20deg); }
  100% { opacity: 0; transform: translateY(-18px) scale(0.7) rotate(55deg); }
}

@media (prefers-reduced-motion: reduce) {
  .word-input-area.success .word-slot,
  .word-input-area.success .word-slot::after {
    animation: none;
  }
}

.word-slot.wrong input {
  color: var(--error);
  border-bottom-color: var(--error);
}

.word-slot .correct-word {
  position: absolute;
  top: -24px;
  font-size: 0.8rem;
  color: var(--success);
  font-family: var(--font-mono);
  white-space: nowrap;
  animation: fadeIn 0.3s ease;
}

.word-slot .slot-punctuation {
  position: absolute;
  right: -10px;
  bottom: 9px;
  font-family: var(--font-mono);
  font-size: 1.6rem;
  color: var(--text-dim);
}

/* Practice controls */
.practice-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 12px;
}

.ctrl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
}

.ctrl-btn-text {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.ctrl-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.ctrl-btn.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.ctrl-btn.primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

.ctrl-btn kbd {
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  color: inherit;
  opacity: 0.75;
  flex-shrink: 0;
}

.ctrl-btn svg {
  flex-shrink: 0;
}

/* Speed control */
.speed-control {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.speed-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.speed-buttons {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
}

.speed-btn {
  padding: 5px 2px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: center;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition);
}

.speed-btn:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.speed-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Accent control */
.accent-control {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}

.accent-control.hidden {
  display: none;
}

.accent-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.accent-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all var(--transition);
}

.accent-btn:hover {
  background: var(--accent-dim);
  color: var(--text-primary);
}

.accent-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.practice-tts-status {
  font-size: 0.76rem;
  color: var(--text-dim);
  line-height: 1.4;
  min-height: 1em;
}

.practice-tts-status.ready {
  color: var(--success);
}

.practice-tts-status.loading {
  color: var(--accent-hover);
}

.practice-tts-status.error {
  color: var(--warning);
}

.practice-tts-status:empty {
  display: none;
}

/* ==================== Virtual Keyboard ==================== */
.practice-container.has-keyboard .practice-center {
  gap: 18px;
}

.practice-container.has-keyboard .word-input-area {
  min-height: 110px;
  padding: 16px 0;
}

.virtual-keyboard {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px;
  background: linear-gradient(180deg, #14142d 0%, #0f0f22 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  display: flex;
  flex-direction: column;
  gap: 6px;
  user-select: none;
  -webkit-user-select: none;
  animation: fadeIn 0.25s ease;
}

.virtual-keyboard.hidden {
  display: none;
}

.kb-row {
  display: grid;
  grid-template-columns: repeat(60, minmax(0, 1fr));
  gap: 6px;
}

.kb-key {
  grid-column: span var(--span, 4);
  position: relative;
  height: 40px;
  padding: 4px 5px;
  border: 1px solid #2e2e58;
  border-bottom-color: #171732;
  border-radius: 8px;
  background: linear-gradient(180deg, #252549 0%, #1b1b37 100%);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 4px 0 #101024,
    0 5px 10px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition:
    transform 0.13s cubic-bezier(0.2, 0.8, 0.2, 1),
    box-shadow 0.14s ease,
    background 0.14s ease,
    border-color 0.14s ease,
    color 0.1s ease;
}

.kb-key:hover {
  background: linear-gradient(180deg, #2c2c57 0%, #212143 100%);
  border-color: #3e3e72;
}

.kb-key-mod {
  background: linear-gradient(180deg, #1d1d3b 0%, #15152e 100%);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.72rem;
  font-weight: 500;
}

.kb-key-mod:hover {
  background: linear-gradient(180deg, #242449 0%, #1a1a38 100%);
  color: var(--text-primary);
}

.kb-key-accent {
  background: linear-gradient(180deg, rgba(124, 108, 240, 0.26) 0%, rgba(95, 79, 212, 0.2) 100%);
  border-color: rgba(124, 108, 240, 0.42);
  color: #dcd7ff;
}

.kb-key-accent:hover {
  background: linear-gradient(180deg, rgba(124, 108, 240, 0.36) 0%, rgba(95, 79, 212, 0.28) 100%);
  border-color: rgba(149, 137, 245, 0.6);
}

.kb-key-dual {
  justify-content: space-between;
  align-items: flex-start;
  padding: 4px 7px 5px;
}

.kb-key-sub {
  font-size: 0.62rem;
  font-weight: 500;
  color: var(--text-dim);
  line-height: 1;
  transition: color 0.1s ease;
}

.kb-key-main {
  font-size: 0.8rem;
  line-height: 1;
  align-self: center;
  transition: color 0.1s ease;
}

.virtual-keyboard.shift-active .kb-key-sub {
  color: var(--text-primary);
}

.virtual-keyboard.shift-active .kb-key-dual .kb-key-main {
  color: var(--text-dim);
}

.kb-key-homing::after {
  content: '';
  position: absolute;
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
  width: 10px;
  height: 2px;
  border-radius: 1px;
  background: rgba(238, 238, 245, 0.28);
  transition: background 0.1s ease;
}

.kb-caps-led {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.virtual-keyboard.caps-active .kb-caps-led {
  background: var(--success);
  box-shadow: 0 0 8px rgba(0, 196, 140, 0.9);
}

.kb-space-bar {
  width: 44px;
  height: 3px;
  border-radius: 2px;
  background: rgba(238, 238, 245, 0.16);
  transition: background 0.1s ease;
}

.virtual-keyboard.ctrl-active .kb-key[data-code="Quote"],
.virtual-keyboard.ctrl-active .kb-key[data-code="Semicolon"] {
  border-color: rgba(124, 108, 240, 0.65);
  box-shadow:
    0 4px 0 #101024,
    0 0 12px rgba(124, 108, 240, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.virtual-keyboard .kb-key.pressed {
  transform: translateY(3px);
  transition-duration: 0.03s;
  background: linear-gradient(180deg, #8778f5 0%, #6858df 100%);
  border-color: #b7abff;
  border-bottom-color: #4b3db6;
  color: #ffffff;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.65);
  box-shadow:
    0 1px 0 #2e2478,
    0 2px 6px rgba(124, 108, 240, 0.45),
    0 0 18px rgba(124, 108, 240, 0.58),
    inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.kb-key.pressed .kb-key-sub,
.kb-key.pressed .kb-key-main {
  color: #ffffff;
}

.kb-key-homing.pressed::after,
.kb-key-space.pressed .kb-space-bar {
  background: rgba(255, 255, 255, 0.9);
}

@media (prefers-reduced-motion: reduce) {
  .kb-key {
    transition: background 0.1s ease, border-color 0.1s ease, color 0.1s ease;
  }

  .virtual-keyboard .kb-key.pressed {
    transform: none;
  }
}

/* ==================== Modals ==================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalIn 0.25s ease;
}

.modal.hidden {
  display: none;
}

@keyframes modalIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
  animation: modalContentIn 0.3s ease;
}

@keyframes modalContentIn {
  from { transform: scale(0.95) translateY(10px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-large {
  width: 90%;
  max-width: 700px;
}

.modal-medium {
  width: 90%;
  max-width: 480px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.2rem;
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* Sentence list in modal */
.sentence-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  margin-bottom: 16px;
}

.sentence-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  transition: background var(--transition);
}

.sentence-item:last-child {
  border-bottom: none;
}

.sentence-item:hover {
  background: var(--bg-card);
}

.sentence-item-index {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  min-width: 24px;
}

.sentence-item-text {
  flex: 1;
  min-width: 0;
}

.sentence-item-en {
  color: var(--text-primary);
  margin-bottom: 2px;
  word-break: break-word;
}

.sentence-item-zh {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.sentence-item-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}

.sentence-item:hover .sentence-item-actions {
  opacity: 1;
}

/* Add sentence form */
.add-sentence-form {
  margin-bottom: 16px;
}

.add-sentence-form h4 {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.add-sentence-form .text-input {
  margin-bottom: 8px;
}

.add-sentence-form .btn {
  margin-top: 4px;
}

/* Bulk import */
.bulk-import {
  margin-top: 16px;
}

.bulk-import summary {
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 8px 0;
}

.bulk-import summary:hover {
  color: var(--accent);
}

.bulk-import-content {
  padding-top: 12px;
}

.help-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.help-text code {
  background: var(--bg-input);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: var(--font-mono);
  color: var(--accent);
}

/* ==================== Summary Modal ==================== */
.summary-body {
  text-align: center;
}

.summary-grade {
  font-size: 4rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a78bfa, var(--success));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 24px;
  letter-spacing: -2px;
  line-height: 1;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

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

.summary-stat-value {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.summary-stat-label {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.summary-detail {
  display: flex;
  justify-content: center;
  gap: 24px;
}

.summary-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.summary-row span:last-child {
  font-family: var(--font-mono);
  font-weight: 600;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot.perfect { background: var(--success); }
.dot.great { background: var(--accent); }
.dot.ok { background: var(--warning); }

/* ==================== Toast ==================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 600;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: toastIn 0.3s ease;
}

.toast.success {
  border-color: rgba(0, 196, 140, 0.3);
  background: var(--success-dim);
}

.toast.error {
  border-color: rgba(255, 71, 87, 0.3);
  background: var(--error-dim);
}

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

/* ==================== Empty State ==================== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 1.3rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.empty-state p {
  color: var(--text-dim);
  margin-bottom: 24px;
}

/* ==================== Responsive ==================== */
@media (max-width: 1024px) {
  .practice-container {
    display: flex;
    flex-direction: column;
    max-width: 800px;
    gap: 14px;
    padding: 16px 20px;
  }

  .practice-side-left {
    gap: 10px;
  }

  .practice-top-bar {
    margin-bottom: 0;
  }

  .practice-side-left .side-panels {
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .practice-stats {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .stat {
    width: auto;
    justify-content: flex-start;
  }

  .practice-center {
    flex: 1;
    gap: 16px;
    padding: 8px 0;
  }

  .practice-controls {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .ctrl-btn {
    width: auto;
    flex: 1 1 auto;
    justify-content: center;
  }

  .side-card-options {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }

  .speed-control {
    flex-direction: row;
    align-items: center;
    flex: 1;
  }

  .speed-buttons {
    display: flex;
    gap: 4px;
  }

  .speed-btn {
    padding: 5px 10px;
  }

  .accent-control {
    flex-direction: row;
    align-items: center;
  }

  .accent-buttons {
    display: flex;
    gap: 4px;
  }

  .kb-toggle-btn {
    width: auto;
  }

  .practice-tts-status {
    flex-basis: 100%;
  }
}

@media (max-width: 768px) {
  #main-header {
    padding: 10px 16px;
  }

  .tagline {
    display: none;
  }

  .view-container {
    padding: 20px 16px;
  }

  .course-grid {
    grid-template-columns: 1fr;
  }

  .practice-container {
    padding: 16px;
  }

  .practice-side-left .side-panels {
    grid-template-columns: 1fr;
  }

  .word-input-area {
    gap: 8px 10px;
    padding: 16px 0;
  }

  .word-slot input,
  .word-slot .word-width {
    font-size: 1.3rem;
  }

  .practice-controls {
    gap: 8px;
  }

  .ctrl-btn {
    padding: 10px 14px;
    font-size: 0.85rem;
  }

  .ctrl-btn kbd {
    display: none;
  }

  .summary-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .modal-content {
    margin: 16px;
  }

  .course-card-actions {
    opacity: 1;
  }

  .virtual-keyboard {
    padding: 8px;
    gap: 4px;
    border-radius: var(--radius-sm);
  }

  .kb-row {
    gap: 4px;
  }

  .kb-key {
    height: 36px;
    font-size: 0.76rem;
    border-radius: 6px;
    padding: 3px 4px;
  }

  .kb-key-mod {
    font-size: 0.64rem;
  }

  .kb-key-dual {
    padding: 3px 4px 4px;
  }

  .kb-key-sub {
    font-size: 0.54rem;
  }

  .kb-key-main {
    font-size: 0.72rem;
  }
}

@media (max-width: 480px) {
  .word-slot input,
  .word-slot .word-width {
    font-size: 1.1rem;
  }

  .practice-stats {
    gap: 8px;
  }

  .stat {
    font-size: 0.8rem;
  }

  .virtual-keyboard {
    padding: 6px;
    gap: 3px;
  }

  .kb-row {
    gap: 3px;
  }

  .kb-key {
    height: 32px;
    font-size: 0.66rem;
    border-radius: 5px;
    box-shadow:
      0 2px 0 #101024,
      0 3px 6px rgba(0, 0, 0, 0.3);
  }

  .virtual-keyboard .kb-key.pressed {
    transform: translateY(2px);
  }

  .kb-key-mod {
    font-size: 0.54rem;
  }

  .kb-key-sub {
    display: none;
  }

  .kb-key-dual {
    justify-content: center;
    align-items: center;
  }

  .kb-key-main {
    font-size: 0.66rem;
  }

  .kb-caps-led {
    top: 4px;
    right: 4px;
    width: 4px;
    height: 4px;
  }

  .kb-space-bar {
    width: 28px;
    height: 2px;
  }
}
