/* ==========================================
   Design System & CSS Variables
   ========================================== */
:root {
  /* Colors - Dark Theme */
  --bg-primary: #0a0a0f;
  --bg-secondary: #13131a;
  --text-primary: #ffffff;
  --text-secondary: #a8a8b3;
  --text-muted: #6b6b7b;

  /* Glass morphism */
  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);

  /* Gradients */
  --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --gradient-accent: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  --gradient-success: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);

  /* Effects */
  --glow-primary: 0 0 40px rgba(102, 126, 234, 0.3);
  --glow-hover: 0 0 60px rgba(102, 126, 234, 0.5);

  /* Spacing */
  --spacing-xs: 0.5rem;
  --spacing-sm: 1rem;
  --spacing-md: 1.5rem;
  --spacing-lg: 2rem;
  --spacing-xl: 3rem;

  /* Typography */
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.5rem;
  --font-size-2xl: 2rem;
  --font-size-3xl: 3rem;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 400ms ease;
}

/* ==========================================
   Global Reset & Base Styles
   ========================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

/* ==========================================
   Background Effects
   ========================================== */
.bg-gradient {
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(118, 75, 162, 0.15) 0%, transparent 50%);
  animation: gradientShift 20s ease infinite;
  pointer-events: none;
  z-index: 0;
}

@keyframes gradientShift {

  0%,
  100% {
    transform: translate(0, 0) rotate(0deg);
  }

  50% {
    transform: translate(-5%, -5%) rotate(5deg);
  }
}

/* ==========================================
   Container & Layout
   ========================================== */
.container {
  position: relative;
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--spacing-lg);
  z-index: 1;
}

/* ==========================================
   Header
   ========================================== */
.header {
  text-align: center;
  margin-bottom: var(--spacing-xl);
  padding-top: var(--spacing-md);
}

.logo {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: var(--spacing-sm);
  display: inline-block;
}

.logo-icon {
  font-size: var(--font-size-3xl);
  margin-right: var(--spacing-xs);
  filter: drop-shadow(var(--glow-primary));
}

.tagline {
  color: var(--text-secondary);
  font-size: var(--font-size-lg);
  font-weight: 300;
}

/* ==========================================
   User Menu & Dropdown
   ========================================== */
.user-menu {
  position: relative;
  display: flex;
  align-items: center;
}

.menu-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 20px;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  padding: 0;
}

.menu-icon:hover {
  background: rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.5);
  transform: scale(1.05);
}

.menu-icon:active {
  transform: scale(0.95);
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  padding: 8px 0;
  z-index: 1000;
  animation: dropdownSlide 0.2s ease-out;
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.dropdown-header {
  padding: 12px 16px;
}

.dropdown-email {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dropdown-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.1);
  margin: 4px 0;
}

.dropdown-item {
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 12px;
}

.dropdown-item:hover {
  background: rgba(102, 126, 234, 0.15);
  color: var(--text-primary);
}

.dropdown-icon {
  font-size: 16px;
  opacity: 0.8;
}


/* ==========================================
   Glass Card Component (NO transform on hover)
   ========================================== */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  transition: border-color var(--transition-base);
  margin-bottom: var(--spacing-md);
}

.glass-card:hover {
  border-color: rgba(102, 126, 234, 0.3);
}

/* ==========================================
   Upload Section
   ========================================== */
.upload-section {
  margin-bottom: var(--spacing-xl);
}

.upload-card {
  padding: var(--spacing-xl);
}

.upload-zone {
  border: 2px dashed var(--glass-border);
  border-radius: var(--radius-md);
  padding: var(--spacing-xl);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-base);
}

.upload-zone:hover {
  border-color: rgba(102, 126, 234, 0.5);
  background: rgba(102, 126, 234, 0.05);
}

.upload-zone.dragover {
  border-color: #667eea;
  background: rgba(102, 126, 234, 0.1);
}

.upload-icon {
  font-size: 4rem;
  margin-bottom: var(--spacing-md);
}

.upload-title {
  font-size: var(--font-size-xl);
  font-weight: 600;
  margin-bottom: var(--spacing-xs);
}

.upload-subtitle {
  color: var(--text-secondary);
  margin-bottom: var(--spacing-sm);
}

.upload-formats {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* Upload Progress */
.upload-progress {
  text-align: center;
  padding: var(--spacing-xl);
}

.progress-spinner {
  width: 60px;
  height: 60px;
  margin: 0 auto var(--spacing-md);
  border: 4px solid rgba(102, 126, 234, 0.2);
  border-top: 4px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.progress-text {
  color: var(--text-secondary);
  font-size: var(--font-size-lg);
  font-weight: 500;
}

/* ==========================================
   Results Section
   ========================================== */
.results-section {
  animation: fadeIn 0.4s ease;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--spacing-md);
  margin-bottom: var(--spacing-md);
}

.stat-card {
  padding: var(--spacing-md);
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.stat-icon {
  font-size: 2rem;
}

.stat-content {
  flex: 1;
  min-width: 0;
}

.stat-value {
  font-size: var(--font-size-xl);
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.125rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.stat-label {
  color: var(--text-secondary);
  font-size: var(--font-size-xs);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ==========================================
   Full Width Word Cloud
   ========================================== */
.viz-card-full {
  padding: var(--spacing-lg);
}

.viz-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
  color: var(--text-primary);
}

.word-cloud {
  width: 100%;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================
   Data Table - Compact
   ========================================== */
.table-card {
  padding: var(--spacing-md);
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm);
  flex-wrap: wrap;
  gap: var(--spacing-sm);
}

.table-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.table-controls {
  display: flex;
  gap: var(--spacing-xs);
  flex-wrap: wrap;
  align-items: center;
}

.file-selector-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}

.file-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.file-checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.file-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.file-checkbox:hover {
  background: rgba(102, 126, 234, 0.1);
  border-color: rgba(102, 126, 234, 0.3);
}

.file-checkbox.active {
  background: rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.5);
  color: var(--text-primary);
}

.file-checkbox.saved-filter {
  background: rgba(255, 193, 7, 0.1);
  border-color: rgba(255, 193, 7, 0.3);
}

.file-checkbox.saved-filter.active {
  background: rgba(255, 193, 7, 0.2);
  border-color: rgba(255, 193, 7, 0.5);
}

.file-checkbox input {
  display: none;
}

.search-input {
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: var(--font-size-sm);
  min-width: 150px;
}

.search-input:focus {
  outline: none;
  border-color: rgba(102, 126, 234, 0.5);
}

.export-btn {
  padding: 6px 12px;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: var(--font-size-sm);
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition-fast);
}

.export-btn:hover {
  opacity: 0.9;
}

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  max-height: 500px;
  overflow-y: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table thead {
  background: #131625;
  /* Solid equivalent of rgba(102, 126, 234, 0.1) on #0a0a0f */
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

/* Column widths */
.col-rank {
  width: 40px;
}

.col-word {
  width: auto;
}

.col-count {
  width: 80px;
}

.col-pct {
  width: 60px;
}

.col-save {
  width: 50px;
  text-align: center;
}

.data-table th {
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast);
}

.data-table th.col-save {
  cursor: default;
}

.data-table th.col-save::after {
  content: none;
}

.data-table th:hover {
  color: var(--text-primary);
}

.data-table th.active {
  color: #667eea;
}

.data-table th.sortable::after {
  content: ' ↕';
  opacity: 0.3;
  font-size: 10px;
}

.data-table th.sortable.active::after {
  opacity: 1;
}

.data-table th.clickable {
  cursor: pointer;
}

.data-table th.clickable::after {
  content: none;
}

.data-table th.clickable.filter-active {
  background: rgba(255, 193, 7, 0.2);
  color: #ffc107;
}

.data-table tbody tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
  background: rgba(102, 126, 234, 0.08);
}

.data-table td {
  padding: 6px 10px;
  font-size: 13px;
}

.data-table td:first-child {
  color: var(--text-muted);
  font-size: 12px;
}

.data-table td:nth-child(2) {
  font-weight: 600;
  color: var(--text-primary);
}

/* Save Button in Table */
.save-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--transition-fast);
  opacity: 0.5;
}

.save-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.1);
}

.save-btn.saved {
  opacity: 1;
}

/* ==========================================
   Saved Words Section
   ========================================== */
.saved-words-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: var(--spacing-sm);
  max-height: 300px;
  overflow-y: auto;
}

.saved-word-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(102, 126, 234, 0.2);
  border: 1px solid rgba(102, 126, 234, 0.3);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background var(--transition-fast);
}

.saved-word-tag:hover {
  background: rgba(102, 126, 234, 0.3);
}

.saved-word-tag .remove-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-muted);
  padding: 0;
  line-height: 1;
}

.saved-word-tag .remove-btn:hover {
  color: #f5576c;
}

.saved-word-count {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 2px;
}

/* ==========================================
   Buttons
   ========================================== */
.action-section {
  text-align: center;
  margin-top: var(--spacing-lg);
}

.primary-btn {
  padding: 12px 24px;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--transition-base);
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-xs);
}

.primary-btn:hover {
  opacity: 0.9;
}

/* ==========================================
   Toast Notifications
   ========================================== */
.toast {
  position: fixed;
  bottom: var(--spacing-lg);
  right: var(--spacing-lg);
  padding: var(--spacing-sm) var(--spacing-md);
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: var(--spacing-xs);
  z-index: 1000;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.error-toast {
  border-left: 4px solid #f5576c;
}

.success-toast {
  border-left: 4px solid #10b981;
}

.toast-icon {
  font-size: var(--font-size-lg);
}

.toast-message {
  color: var(--text-primary);
  font-weight: 500;
  font-size: var(--font-size-sm);
}

/* ==========================================
   Animations
   ========================================== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ==========================================
   Responsive Design
   ========================================== */
/* ==========================================
   Responsive Design
   ========================================== */
@media (max-width: 768px) {
  .container {
    padding: var(--spacing-sm);
  }

  .logo {
    font-size: var(--font-size-2xl);
  }

  .logo-icon {
    font-size: var(--font-size-2xl);
  }

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

  /* Table responsive styles */
  .table-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .data-table thead {
    background: var(--bg-secondary);
    /* Solid background to prevent overlap translucency */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    /* separation shadow */
  }

  /* Reduce padding for graphs on mobile */
  .viz-card-full {
    padding: var(--spacing-sm);
  }

  .table-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .file-selector-container {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  .search-input {
    width: 100%;
  }

  .export-btn {
    width: 100%;
    margin-top: 8px;
  }

  /* Hide less important columns on mobile */
  .col-pct,
  .data-table td:nth-child(4) {
    display: none;
  }

  .toast {
    left: var(--spacing-sm);
    right: var(--spacing-sm);
    bottom: var(--spacing-sm);
  }

  /* Modal responsive */
  .modal-content {
    width: 95%;
    max-height: 90vh;
  }

  .flashcard-container {
    width: 95%;
    height: 80vh;
    padding: 1rem;
  }

  .flashcard-front h3 {
    font-size: 2rem;
  }
}

/* ==========================================
   Professional Footer
   ========================================== */
.app-footer {
  margin-top: 4rem;
  padding: 2rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.footer-copy {
  font-weight: 500;
}

.footer-separator {
  opacity: 0.5;
}

.footer-version {
  padding: 2px 8px;
  background: rgba(102, 126, 234, 0.15);
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #667eea;
}

.footer-right {
  display: flex;
  gap: 1.5rem;
  align-items: center;
}

.footer-link {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0;
  font-family: inherit;
}

.footer-link:hover {
  color: #667eea;
}

.footer-link span {
  font-size: 1rem;
}

@media (max-width: 768px) {
  .footer-content {
    flex-direction: column;
    text-align: center;
  }

  .footer-left {
    flex-direction: column;
    gap: 0.5rem;
  }

  .footer-separator {
    display: none;
  }
}


@media (max-width: 480px) {
  .upload-icon {
    font-size: 3rem;
  }

  .upload-title {
    font-size: 1.25rem;
  }
}


/* ==========================================
   Scrollbar Styling
   ========================================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.3);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.5);
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.modal-content {
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  padding: 0;
  overflow: hidden;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  margin: 0;
  font-size: 1.5rem;
  color: white;
}

.highlight-text {
  color: #a78bfa;
  font-weight: 700;
}

.close-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.close-btn:hover {
  opacity: 1;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  max-height: calc(80vh - 80px);
}

.context-item {
  background: rgba(255, 255, 255, 0.05);
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  border-left: 3px solid #a78bfa;
  font-size: 1rem;
  line-height: 1.5;
  color: #e2e8f0;
}

.context-item strong {
  color: #a78bfa;
  background: rgba(167, 139, 250, 0.1);
  padding: 0 4px;
  border-radius: 4px;
}

.context-item.context-dict {
  border-left-color: #3b82f6;
  background: rgba(59, 130, 246, 0.05);
}

.context-item.context-dict strong {
  color: #60a5fa;
  background: rgba(59, 130, 246, 0.15);
}

/* Source Badges and Dictionary Context */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 4px;
  letter-spacing: 0.3px;
  vertical-align: middle;
}

.badge-source {
  background: rgba(167, 139, 250, 0.2);
  color: #c4b5fd;
  border: 1px solid rgba(167, 139, 250, 0.4);
  margin-left: 8px;
  font-weight: 500;
}

/* Source Icon Badges */
.source-icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  vertical-align: middle;
  margin-left: 8px;
  position: relative;
  flex-shrink: 0;
}

.source-icon-badge:hover {
  transform: scale(1.1);
}

.source-icon-badge .badge-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: calc(100% + 8px);
  bottom: auto;
  left: 0;
  transform: none;
  background: rgba(15, 23, 42, 0.96);
  color: #f8fafc;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  width: max-content;
  max-width: 290px;
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.35;
  text-align: left;
  pointer-events: none;
  z-index: 9999;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.source-icon-badge .badge-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  top: auto;
  left: 8px;
  margin-left: 0;
  border-width: 5px;
  border-style: solid;
  border-color: transparent transparent rgba(15, 23, 42, 0.96) transparent;
}

.source-icon-badge:hover .badge-tooltip {
  visibility: visible;
  opacity: 1;
}

.source-icon-badge.lingoes-badge,
.lingoes-badge {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.35);
}

.source-icon-badge.lingoes-badge:hover,
.lingoes-badge:hover {
  background: rgba(34, 197, 94, 0.25);
  border-color: #22c55e;
  box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

.wiktionary-badge {
  background: linear-gradient(135deg, #0284c7 0%, #0d9488 100%);
  box-shadow: 0 2px 6px rgba(13, 148, 136, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.wiktionary-badge:hover {
  box-shadow: 0 3px 10px rgba(13, 148, 136, 0.45);
}

.datamuse-badge {
  background: linear-gradient(135deg, #f59e0b 0%, #ea580c 100%);
  box-shadow: 0 2px 6px rgba(234, 88, 12, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.datamuse-badge:hover {
  box-shadow: 0 3px 10px rgba(234, 88, 12, 0.45);
}

.default-source-badge {
  background: linear-gradient(135deg, #64748b 0%, #475569 100%);
  box-shadow: 0 2px 6px rgba(71, 85, 105, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Clickable Lemma Badge */
.lemma-wrapper {
  display: inline-flex;
  align-items: center;
  font-size: 0.85rem;
  font-weight: normal;
  color: #94a3b8;
  margin-left: 8px;
  vertical-align: middle;
}

.lemma-badge-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(167, 139, 250, 0.15);
  color: #c4b5fd;
  border: 1px solid rgba(167, 139, 250, 0.4);
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  margin-left: 4px;
  transition: all 0.2s ease;
  font-family: inherit;
  line-height: 1.4;
}

.lemma-badge-btn:hover {
  background: rgba(167, 139, 250, 0.35);
  color: #ffffff;
  border-color: #a78bfa;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(167, 139, 250, 0.25);
}

.lemma-badge-btn:active {
  transform: translateY(0);
}

/* Lemma Context Hint & Quick Action */
.lemma-context-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  background: rgba(167, 139, 250, 0.12);
  border: 1px solid rgba(167, 139, 250, 0.35);
  border-left: 4px solid #a78bfa;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 1rem;
  color: #e2e8f0;
  font-size: 0.92rem;
  line-height: 1.5;
}

.lemma-context-hint strong {
  color: #c4b5fd;
  font-weight: 600;
}

.btn-subtle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(167, 139, 250, 0.2);
  color: #ede9fe;
  border: 1px solid rgba(167, 139, 250, 0.5);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-subtle:hover {
  background: rgba(167, 139, 250, 0.4);
  color: #ffffff;
  border-color: #c4b5fd;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(167, 139, 250, 0.3);
}

.btn-subtle:active {
  transform: translateY(0);
}

.badge-dict {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.4);
  margin-bottom: 4px;
}

.dict-subtext {
  font-size: 0.8rem;
  color: #94a3b8;
  font-style: italic;
  margin-bottom: 8px;
}

.example-translation {
  margin-top: 8px;
  font-size: 0.9rem;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.04);
  padding: 4px 8px;
  border-radius: 4px;
  border-left: 2px solid #3b82f6;
}

/* Provenance Tooltip (shows ONLY on hover) */
.context-provenance {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  cursor: pointer;
  vertical-align: middle;
}

.context-provenance .provenance-icon {
  font-size: 0.95rem;
  opacity: 0.65;
  transition: opacity 0.2s, transform 0.2s;
  user-select: none;
}

.context-provenance:hover .provenance-icon {
  opacity: 1;
  transform: scale(1.15);
}

.context-provenance .provenance-tooltip {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #f1f5f9;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 500;
  width: max-content;
  max-width: 320px;
  white-space: normal;
  word-wrap: break-word;
  line-height: 1.35;
  text-align: center;
  z-index: 9999;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.context-provenance .provenance-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #0f172a transparent transparent transparent;
}

.context-provenance:hover .provenance-tooltip {
  visibility: visible;
  opacity: 1;
}

.phonetic-container {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}

/* Button variants */
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background 0.2s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.col-actions {
  width: 100px;
  text-align: right;
}

/* Definition Styles */
.section-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 1.1rem;
  font-weight: 600;
  color: #fff;
  margin: 1.5rem 0 0.5rem 0;
  border-bottom: 2px solid rgba(167, 139, 250, 0.3);
  padding-bottom: 6px;
}

.definitions-section {
  margin-bottom: 1.5rem;
}

.definition-group {
  margin-bottom: 1rem;
}

.part-of-speech {
  display: inline-block;
  background: rgba(167, 139, 250, 0.15);
  border: 1px solid rgba(167, 139, 250, 0.3);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.78rem;
  font-weight: 500;
  font-style: normal;
  color: #c4b5fd;
  margin-top: 2px;
  margin-bottom: 6px;
  letter-spacing: 0.2px;
}

.def-list {
  margin: 0;
  padding-left: 1.2rem;
  list-style-type: disc;
}

.def-list li {
  margin-bottom: 4px;
  color: #e2e8f0;
}

.loading,
.no-data,
.error-text {
  color: #cbd5e1;
  font-style: italic;
  padding: 1rem 0;
}

/* Flashcards Section */
.flashcards-section {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(10px);
}

.flashcard-container {
  width: 90%;
  max-width: 500px;
  height: 600px;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
}

.flashcard-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.flashcard-header h2 {
  color: white;
  margin: 0;
}

.flashcard {
  flex: 1;
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 2rem;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  text-align: center;
  transition: transform 0.6s;
  transform-style: preserve-3d;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.flashcard-back {
  transform: rotateY(180deg);
  background: rgba(0, 0, 0, 0.4);
  border-radius: 16px;
}

.flashcard-front h3 {
  font-size: 3rem;
  color: #fff;
  margin: 0 0 1rem 0;
}

.fc-hint {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.9rem;
}

.fc-content {
  font-size: 1.1rem;
  color: #e2e8f0;
  margin-bottom: 1.5rem;
  max-height: 40%;
  overflow-y: auto;
}

.fc-context {
  font-size: 0.95rem;
  color: #a78bfa;
  font-style: italic;
  margin-bottom: 2rem;
  padding: 1rem;
  background: rgba(167, 139, 250, 0.1);
  border-radius: 8px;
}

.fc-actions {
  display: flex;
  gap: 1rem;
  width: 100%;
  justify-content: center;
}

.srs-btn {
  padding: 0.8rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  color: white;
  transition: transform 0.2s;
}

.srs-btn:hover {
  transform: scale(1.05);
}

.srs-btn.again {
  background: #ef4444;
}

.srs-btn.hard {
  background: #f59e0b;
}

.srs-btn.good {
  background: #3b82f6;
}

.srs-btn.easy {
  background: #10b981;
}

.fc-progress {
  text-align: center;
  color: rgba(255, 255, 255, 0.7);
}

/* Login UI */
.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm);
}

.secondary-btn.small {
  padding: 6px 12px;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  border-radius: 8px;
  cursor: pointer;
}

.secondary-btn.small:hover {
  background: rgba(255, 255, 255, 0.2);
}

.micro-modal {
  max-width: 400px;
}

.input-field {
  width: 100%;
  padding: 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: white;
  margin-bottom: 1rem;
  font-size: 1rem;
}

.input-field:focus {
  outline: none;
  border-color: #667eea;
}

.primary-btn.full-width {
  width: 100%;
  justify-content: center;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  text-decoration: underline;
  cursor: pointer;
  margin-top: 1rem;
  font-size: 0.9rem;
}

.modal-desc {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.user-email {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .header-top {
    flex-direction: column;
    gap: 1rem;
  }
}

/* File Chips */
.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  border-radius: 16px;
  padding-right: 8px;
  /* space for delete btn */
  transition: all var(--transition-fast);
}

.file-chip.active {
  background: rgba(102, 126, 234, 0.2);
  border-color: rgba(102, 126, 234, 0.5);
}

.file-chip .file-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0 4px 10px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 12px;
}

.file-chip.active .file-label {
  color: var(--text-primary);
}

.file-chip input {
  display: none;
}

.delete-file-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 2px;
}

.delete-file-btn:hover {
  background: rgba(245, 87, 108, 0.2);
  color: #f5576c;
}

/* Interactive Table Rows */
.word-row {
  cursor: pointer;
}

.word-cell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tts-hover-btn {
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 14px;
  padding: 2px;
}

.word-row:hover .tts-hover-btn {
  opacity: 1;
}

/* Remove default button styles */
.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
}

/* Status Icons & Background Analysis Messaging */
.status-icon {
  font-size: 0.9rem;
  margin-right: 6px;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
}

.spinner-dot {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(167, 139, 250, 0.2);
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: spin-simple 0.8s linear infinite;
  display: inline-block;
}

@keyframes spin-simple {
  to {
    transform: rotate(360deg);
  }
}

.status-icon.complete {
  color: #10b981;
}

.status-icon.error {
  color: #ef4444;
}

.context-item.info-message {
  background: rgba(102, 126, 234, 0.1) !important;
  border-left: 4px solid #667eea !important;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 12px;
  color: #a8a8b3;
}

.context-item.info-message .spinner-dot {
  width: 18px;
  height: 18px;
}

/* Mobile Card View (Table Optimization) */
@media screen and (max-width: 768px) {

  /* Hide standard table headers */
  .data-table thead {
    display: none;
  }

  /* Make rows behave like cards */
  .data-table tbody tr {
    display: block;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    padding: 12px;
  }

  .data-table tbody tr:hover {
    background: rgba(102, 126, 234, 0.1);
  }

  /* Make cells behave like list items */
  .data-table td {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    text-align: right;
  }

  .data-table td:last-child {
    border-bottom: none;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
  }

  /* Add labels via pseudo-elements */
  .data-table td::before {
    content: attr(data-label);
    font-weight: 500;
    color: var(--text-muted);
    text-align: left;
    margin-right: 12px;
  }
}

/* ==========================================
   Phrase & Enhanced Vocabulary System
   ========================================== */
.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ==========================================
   Table Action Buttons Unified Design
   ========================================== */
.table-btn-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-action-btn,
.primary-btn-sm,
.secondary-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 13px;
  border-radius: 8px;
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  box-sizing: border-box;
  text-decoration: none;
  line-height: 1;
}

.table-action-btn:hover,
.primary-btn-sm:hover,
.secondary-btn-sm:hover {
  transform: translateY(-1px);
}

.table-action-btn:active,
.primary-btn-sm:active,
.secondary-btn-sm:active {
  transform: translateY(0);
}

/* Primary Accent (➕ Thêm từ/cụm từ) */
.table-action-btn.btn-primary,
.primary-btn-sm {
  background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
}

.table-action-btn.btn-primary:hover,
.primary-btn-sm:hover {
  background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.45);
}

/* Feature Accent (🎴 Flashcards) */
.table-action-btn.btn-feature {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34d399;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.15);
}

.table-action-btn.btn-feature:hover {
  background: rgba(16, 185, 129, 0.28);
  border-color: #10b981;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
}

/* Neutral Secondary (🧬 Book DNA, 🗂️ Anki, 📥 CSV) */
.table-action-btn.btn-secondary,
.secondary-btn-sm {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #e2e8f0;
}

.table-action-btn.btn-secondary:hover,
.secondary-btn-sm:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.3);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.badge-phrase {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 9999px;
  background: rgba(236, 72, 153, 0.18);
  color: #f472b6;
  border: 1px solid rgba(236, 72, 153, 0.35);
  margin-left: 6px;
  vertical-align: middle;
}

.badge-word {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 9999px;
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
  margin-left: 6px;
  vertical-align: middle;
}

.phrase-meaning-preview {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 3px;
  font-style: italic;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.phrase-modal {
  max-width: 520px;
}

.phrase-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.phrase-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.phrase-form .form-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.phrase-form label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.phrase-form .input-with-action {
  display: flex;
  gap: 8px;
  align-items: center;
}

.phrase-form .input-with-action .input-field {
  flex: 1;
}

.phrase-form textarea.input-field {
  resize: vertical;
  min-height: 54px;
}

.phrase-form .form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}

.floating-save-btn {
  position: absolute;
  z-index: 2000;
  background: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
  color: #ffffff;
  border: none;
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  transform: translateY(-100%);
  transition: transform 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.floating-save-btn:hover {
  transform: translateY(-100%) scale(1.04);
  box-shadow: 0 6px 20px rgba(236, 72, 153, 0.4);
}

.fc-type-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 10px;
  border-radius: 12px;
  margin-bottom: 10px;
}

.fc-type-badge.phrase {
  background: rgba(236, 72, 153, 0.2);
  color: #f472b6;
  border: 1px solid rgba(236, 72, 153, 0.4);
}

.fc-type-badge.word {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.fc-word-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.fc-custom-meaning {
  margin-bottom: 12px;
  padding: 10px 14px;
  background: rgba(236, 72, 153, 0.12);
  border-left: 3px solid #ec4899;
  border-radius: 6px;
  text-align: left;
}

.fc-custom-meaning-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #f472b6;
  margin-bottom: 4px;
}

.fc-custom-meaning-text {
  font-size: 1rem;
  color: #ffffff;
  font-weight: 500;
}

.saved-filter-tabs {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  margin-left: 8px;
  vertical-align: middle;
}

.saved-tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.saved-tab-btn:hover {
  color: var(--text-primary);
}

.saved-tab-btn.active {
  background: var(--gradient-primary);
  color: #ffffff;
  font-weight: 600;
}

/* ==========================================
   CEFR Radar & Level Badges
   ========================================== */
.cefr-radar-card {
  margin-bottom: 1.5rem;
  padding: 1.25rem 1.5rem;
}

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

.cefr-radar-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px 0;
}

.cefr-radar-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
}

.cefr-badge-large {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 6px 16px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.cefr-progress-bar {
  display: flex;
  height: 14px;
  border-radius: 7px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  margin-bottom: 12px;
}

.cefr-bar-segment {
  height: 100%;
  transition: width 0.5s ease-in-out;
}

.seg-a1 { background: #10b981; }
.seg-a2 { background: #3b82f6; }
.seg-b1 { background: #f59e0b; }
.seg-b2 { background: #ec4899; }
.seg-c1 { background: #8b5cf6; }
.seg-c2 { background: #6366f1; }

.cefr-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

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

.dot-a1 { background: #10b981; }
.dot-a2 { background: #3b82f6; }
.dot-b1 { background: #f59e0b; }
.dot-b2 { background: #ec4899; }
.dot-c1 { background: #8b5cf6; }
.dot-c2 { background: #6366f1; }

.badge-cefr {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.badge-a1 { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.35); }
.badge-a2 { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid rgba(59, 130, 246, 0.35); }
.badge-b1 { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.35); }
.badge-b2 { background: rgba(236, 72, 153, 0.15); color: #f472b6; border: 1px solid rgba(236, 72, 153, 0.35); }
.badge-c1 { background: rgba(139, 92, 246, 0.15); color: #a78bfa; border: 1px solid rgba(139, 92, 246, 0.35); }
.badge-c2 { background: rgba(99, 102, 241, 0.15); color: #818cf8; border: 1px solid rgba(99, 102, 241, 0.35); }
.badge-cefr-empty { color: var(--text-muted); font-size: 0.8rem; }

.cefr-filter-select {
  background: var(--glass-bg);
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}

.tts-btn {
  font-size: 15px;
  padding: 4px;
  min-width: 32px;
  min-height: 32px;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

.tts-btn:hover, .tts-btn:active {
  opacity: 1;
  transform: scale(1.15);
}

/* Multi-Screen Mobile & Responsive Styles */
@media screen and (max-width: 768px) {
  .table-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  
  .table-controls .search-input {
    width: 100%;
  }

  .table-controls .cefr-filter-select {
    width: 100%;
  }

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

  .stat-card {
    padding: 12px;
  }

  .stat-value {
    font-size: 1.35rem;
  }

  .modal-content {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    overflow-y: auto !important;
  }

  .flashcard-container {
    padding: 1rem;
    min-height: 380px;
  }

  .flashcard {
    min-height: 260px;
  }

  .fc-rating-buttons {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .fc-rating-btn {
    padding: 12px 8px !important;
    font-size: 0.9rem !important;
    min-height: 44px !important;
  }
}

@media screen and (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .cefr-legend {
    gap: 8px;
    font-size: 0.78rem;
  }
}

/* ==========================================
   Book DNA Infographic Modal Styles
   ========================================== */
.dna-modal-content {
  max-width: 900px !important;
  width: 95% !important;
  background: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid rgba(255, 255, 255, 0.15) !important;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7) !important;
}

.dna-desc {
  color: #94a3b8;
  font-size: 0.92rem;
  margin-bottom: 1rem;
}

.dna-canvas-wrapper {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #0b0f19;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.dna-canvas-wrapper canvas {
  width: 100%;
  height: auto;
  display: block;
}

.dna-actions {
  display: flex;
  gap: 12px;
  margin-top: 1.25rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

@media screen and (max-width: 600px) {
  .dna-actions {
    justify-content: stretch;
  }
  .dna-actions button {
    flex: 1 1 100%;
    justify-content: center;
  }
}

/* ==========================================
   Table View Switcher Tabs & Known Words Toggle
   ========================================== */
.table-view-tabs {
  display: flex;
  gap: 8px;
  padding: 1rem 1.5rem 0.5rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  overflow-x: auto;
  scrollbar-width: none;
}

.table-view-tabs::-webkit-scrollbar {
  display: none;
}

.table-view-tab {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.table-view-tab:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #f1f5f9;
}

.table-view-tab.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(56, 189, 248, 0.2));
  border-color: #6366f1;
  color: #ffffff;
  font-weight: 600;
}

.tab-badge {
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 7px;
  border-radius: 12px;
  font-size: 0.75rem;
  color: #e2e8f0;
}

.table-view-tab.active .tab-badge {
  background: rgba(99, 102, 241, 0.5);
  color: #ffffff;
}

.table-title-area {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.known-filter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: #94a3b8;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  user-select: none;
}

.known-filter-toggle input[type="checkbox"] {
  accent-color: #10b981;
  cursor: pointer;
}

.known-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  opacity: 0.6;
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s;
}

.known-btn:hover {
  opacity: 1;
  transform: scale(1.15);
}

.known-btn.is-known {
  opacity: 1;
  filter: drop-shadow(0 0 4px #10b981);
}

tr.is-known-row {
  opacity: 0.45;
}

tr.is-known-row td.col-word,
tr.is-known-row .word-text {
  text-decoration: line-through;
  color: #64748b;
}

/* Collocation pill tag */
.colloc-badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 4px;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  margin-left: 6px;
}

/* Book Readiness Pill */
.readiness-pill {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #10b981;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.88rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.1);
}

.readiness-pill b {
  font-size: 1rem;
  font-weight: 700;
  color: #34d399;
}
