:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #818cf8;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border: #2d3748;
  --success: #10b981;
  --error: #ef4444;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Offline banner */
.offline-banner {
  background: rgba(245, 158, 11, 0.12);
  border-bottom: 1px solid rgba(245, 158, 11, 0.35);
  padding: 0.5rem 1.5rem;
  text-align: center;
  font-size: 0.825rem;
  color: #fbbf24;
  display: none;
}
.offline-banner.show { display: block; }

/* Header */
.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo { display: flex; align-items: center; gap: 0.75rem; }

.logo-icon {
  width: 38px;
  height: 38px;
  background: var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: bold;
  flex-shrink: 0;
}

.logo-text h1 { font-size: 1.1rem; font-weight: 700; }
.logo-text span { font-size: 0.75rem; color: var(--text-secondary); }

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.875rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  background: rgba(79, 70, 229, 0.12);
  border: 1px solid rgba(79, 70, 229, 0.3);
  color: var(--accent-light);
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-light);
  flex-shrink: 0;
}

.status-badge.ready {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
  color: #34d399;
}
.status-badge.ready .status-dot {
  background: #34d399;
  animation: pulse 2s infinite;
}
.status-badge.error {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
.status-badge.error .status-dot { background: var(--error); }

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

/* Container */
.container {
  flex: 1;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Loading section */
.loading-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 3rem 2rem;
  text-align: center;
}

.loading-icon { font-size: 3.5rem; margin-bottom: 1rem; }
.loading-title { font-size: 1.3rem; font-weight: 700; margin-bottom: 0.6rem; }
.loading-desc {
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.7;
  margin-bottom: 2rem;
}

.progress-container {
  background: rgba(255,255,255,0.06);
  border-radius: 8px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 0.875rem;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  border-radius: 8px;
  width: 0%;
  transition: width 0.4s ease;
}
.progress-text { font-size: 0.8rem; color: var(--text-secondary); }

/* Translation section */
.translation-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
.translation-section.hidden { display: none; }

/* Language bar */
.lang-bar { display: flex; align-items: center; gap: 1rem; }

.lang-tag {
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-card);
}
.lang-tag.zh { color: #f59e0b; border-color: rgba(245,158,11,0.3); background: rgba(245,158,11,0.06); }
.lang-tag.en { color: #06b6d4; border-color: rgba(6,182,212,0.3); background: rgba(6,182,212,0.06); }

.arrow-icon { flex: 1; text-align: center; color: var(--text-secondary); font-size: 1.25rem; }

/* Input card */
.textarea-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  transition: border-color 0.2s;
}
.textarea-card:focus-within { border-color: var(--accent); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.8rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}

.card-label {
  font-size: 0.775rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}
.char-count { font-size: 0.75rem; color: var(--text-secondary); }
.card-actions { display: flex; gap: 0.5rem; }

textarea {
  width: 100%;
  min-height: 150px;
  padding: 1.25rem;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1.75;
  resize: vertical;
  font-family: inherit;
  outline: none;
}
textarea::placeholder { color: rgba(148, 163, 184, 0.35); }

/* Output card */
.output-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.output-content {
  padding: 1.25rem;
  min-height: 150px;
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text-primary);
  user-select: text;
  white-space: pre-wrap;
  word-break: break-word;
}
.output-content.placeholder { color: rgba(148, 163, 184, 0.35); font-style: italic; }
.output-content.translating { color: var(--text-secondary); }

/* Icon buttons */
.icon-btn {
  padding: 0.3rem 0.7rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-secondary);
  font-size: 0.775rem;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
}
.icon-btn:hover {
  border-color: var(--accent-light);
  color: var(--accent-light);
  background: rgba(79, 70, 229, 0.1);
}
.icon-btn.speaking {
  border-color: var(--success);
  color: var(--success);
  background: rgba(16, 185, 129, 0.1);
  animation: speaking-pulse 1s ease-in-out infinite;
}
@keyframes speaking-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

/* Action bar */
.action-bar {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.translate-btn {
  flex: 1;
  padding: 0.875rem 2rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
}
.translate-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 8px 28px rgba(79, 70, 229, 0.38);
}
.translate-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.shortcut-hint { font-size: 0.75rem; color: var(--text-secondary); white-space: nowrap; }
.shortcut-hint kbd {
  padding: 0.125rem 0.375rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.7rem;
  font-family: inherit;
}

/* Voice selector row */
.voice-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.voice-row-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
}
.voice-select {
  flex: 1;
  min-width: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-primary);
  font-size: 0.8rem;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.voice-select:focus { border-color: var(--accent-light); }
.voice-select option { background: #1a1a2e; color: var(--text-primary); }
.voice-tip {
  font-size: 0.75rem;
  color: var(--success);
  white-space: nowrap;
}

/* Info */
.info-section {
  background: rgba(79, 70, 229, 0.05);
  border: 1px solid rgba(79, 70, 229, 0.2);
  border-radius: 12px;
  padding: 0.875rem 1.25rem;
  font-size: 0.845rem;
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  line-height: 1.6;
}
.info-icon { flex-shrink: 0; margin-top: 0.05rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120px);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: transform 0.3s ease;
  z-index: 1000;
  box-shadow: 0 12px 40px rgba(0,0,0,0.55);
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  flex-shrink: 0;
}

/* Responsive */
@media (max-width: 600px) {
  .container { padding: 1rem; }
  .logo-text span { display: none; }
  .shortcut-hint { display: none; }
  .loading-section { padding: 2rem 1.25rem; }
}

/* ── Tab navigation ────────────────────────────────────────────────────────── */
.tab-nav {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 1.5rem;
}
.tab-btn {
  padding: 0.75rem 1.35rem;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent-light); border-bottom-color: var(--accent-light); }
.tab-btn:hover:not(.active) { color: var(--text-primary); }

/* ── Learn view ─────────────────────────────────────────────────────────────── */
#view-learn {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}
#view-learn.hidden { display: none; }

/* Category pills */
.cat-bar {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cat-bar::-webkit-scrollbar { display: none; }

.cat-btn {
  padding: 0.45rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s;
  font-family: inherit;
  flex-shrink: 0;
}
.cat-btn.active { background: var(--accent); border-color: var(--accent); color: white; }
.cat-btn:hover:not(.active) { border-color: var(--accent-light); color: var(--accent-light); }

/* Mode bar */
.mode-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.mode-btn {
  padding: 0.4rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.18s;
  font-family: inherit;
}
.mode-btn.active {
  background: rgba(79, 70, 229, 0.18);
  border-color: var(--accent);
  color: var(--accent-light);
}
.known-label { margin-left: auto; font-size: 0.8rem; color: var(--success); }

/* Word list */
.word-list { display: flex; flex-direction: column; gap: 0.625rem; }

.word-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.875rem 1.125rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: border-color 0.18s;
}
.word-card.known {
  border-color: rgba(16, 185, 129, 0.3);
  background: rgba(16, 185, 129, 0.04);
}
.word-card-text { flex: 1; min-width: 0; }
.word-en { font-size: 1.1rem; font-weight: 600; color: var(--text-primary); line-height: 1.3; }
.word-zh { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.2rem; }

.word-speak-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(79, 70, 229, 0.1);
  border: 1px solid rgba(79, 70, 229, 0.22);
  color: var(--accent-light);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
  flex-shrink: 0;
}
.word-speak-btn:hover { background: rgba(79, 70, 229, 0.22); transform: scale(1.08); }
.word-speak-btn.speaking {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.4);
  color: var(--success);
  animation: speaking-pulse 1s ease-in-out infinite;
}

/* Flashcard */
.flashcard-wrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}
.fc-progress {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
}
.fc-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.35s ease;
  width: 0%;
}
.fc-counter { font-size: 0.8rem; color: var(--text-secondary); text-align: right; }

.flashcard {
  min-height: 210px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, transform 0.15s;
  gap: 0.75rem;
  user-select: none;
}
.flashcard:hover:not(.revealed) { border-color: rgba(79, 70, 229, 0.4); transform: translateY(-2px); }
.flashcard.revealed { border-color: rgba(16, 185, 129, 0.4); cursor: default; }

.fc-zh { font-size: 2rem; font-weight: 700; color: var(--text-primary); }
.fc-en { font-size: 1.6rem; font-weight: 600; color: var(--accent-light); }
.fc-hint { font-size: 0.8rem; color: var(--text-secondary); }

.fc-btns { display: flex; gap: 1rem; }
.fc-btn {
  flex: 1;
  padding: 0.875rem;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.18s;
}
.fc-btn.unknown {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
.fc-btn.know {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
}
.fc-btn:hover { filter: brightness(1.2); transform: translateY(-1px); }

/* Done card */
.done-card {
  text-align: center;
  padding: 3rem 2rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}
.done-icon { font-size: 3.5rem; }
.done-title { font-size: 1.3rem; font-weight: 700; margin-top: 0.5rem; }
.done-score { color: var(--text-secondary); font-size: 0.95rem; }
.done-card .translate-btn { margin-top: 1.5rem; max-width: 220px; }
