/* -------------------------------------------------------------
   Parsi Sareh Dictionary - Modern Stylesheet
   ------------------------------------------------------------- */

:root {
  --font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Tahoma, sans-serif;
  
  /* Light Theme */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-text: #1d4ed8;
  
  --loan-word-bg: #fee2e2;
  --loan-word-text: #b91c1c;
  --loan-word-border: #fca5a5;
  
  --sareh-bg: #ecfdf5;
  --sareh-text: #047857;
  --sareh-border: #a7f3d0;
  --sareh-chip-hover: #d1fae5;
  
  --tag-bg: #f3f4f6;
  --tag-text: #4b5563;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

body.dark {
  --bg-primary: #090d16;
  --bg-secondary: #131a29;
  --bg-tertiary: #1e293b;
  --bg-card: #131c2e;
  --bg-card-hover: #19253d;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --border-color: #243049;
  --border-focus: #60a5fa;
  
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #1e293b;
  --primary-text: #93c5fd;
  
  --loan-word-bg: #3c1618;
  --loan-word-text: #fca5a5;
  --loan-word-border: #7f1d1d;
  
  --sareh-bg: #063625;
  --sareh-text: #6ee7b7;
  --sareh-border: #065f46;
  --sareh-chip-hover: #0b4933;
  
  --tag-bg: #1e293b;
  --tag-text: #cbd5e1;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.5);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.5);
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

button, input, select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.25rem;
  width: 100%;
}

/* Header */
.header {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
  background-color: rgba(var(--bg-secondary), 0.9);
  transition: var(--transition);
  padding-top: env(safe-area-inset-top, 0);
}

.header-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.85rem;
  padding-bottom: 0.85rem;
  gap: 1rem;
}

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

.logo-icon {
  font-size: 2rem;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.logo-title {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.logo-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.5rem 0.9rem;
  font-family: var(--font-family);
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-outline {
  background-color: var(--bg-tertiary);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background-color: var(--primary-light);
}

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

.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-icon {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  padding: 0;
  font-size: 1.15rem;
}

.btn-icon:hover {
  border-color: var(--primary);
  transform: scale(1.05);
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.btn-danger {
  background-color: #ef4444;
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #dc2626;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-sm {
  background-color: var(--primary);
  color: #ffffff;
  padding: 0.1rem 0.4rem;
  font-size: 0.7rem;
}

/* Hero Section */
.hero-section {
  padding: 2.25rem 0 1.5rem;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border-bottom: 1px solid var(--border-color);
  text-align: center;
}

.stats-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 1.5rem;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Search Box */
.search-box-wrapper {
  max-width: 780px;
  margin: 0 auto 1.5rem;
}

.search-input-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.search-input-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15), var(--shadow-lg);
}

.search-icon {
  font-size: 1.25rem;
  padding: 0 1rem;
  color: var(--text-muted);
}

#searchInput {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 1rem 0;
  font-size: 1.15rem;
  font-family: var(--font-family);
  color: var(--text-primary);
  outline: none;
}

#searchInput::placeholder {
  color: var(--text-muted);
  font-size: 0.98rem;
}

.clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 1rem;
  font-size: 1.15rem;
  border-radius: 50%;
  transition: var(--transition);
}

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

/* Search Modes */
.search-modes {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin-top: 0.85rem;
  flex-wrap: wrap;
}

.mode-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-family);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.mode-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.mode-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
}

/* Alphabet Filter Bar */
.alphabet-bar-container {
  max-width: 900px;
  margin: 0 auto;
}

.alphabet-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.alphabet-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.25rem;
}

.alpha-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.25rem 0.55rem;
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  min-width: 30px;
}

.alpha-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-1px);
}

.alpha-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Main Content Area */
.main-content {
  flex: 1;
  padding-top: 1.75rem;
  padding-bottom: 3rem;
}

/* Results Top Bar */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
  scroll-margin-top: 75px;
}

.results-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.92rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.filter-tag {
  background: var(--primary-light);
  color: var(--primary);
  padding: 0.2rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.results-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}

.source-filter, .sort-filter {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.65rem;
  font-family: var(--font-family);
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
  transition: var(--transition);
}

select:focus {
  border-color: var(--primary);
}

/* Words Grid */
.words-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 1.25rem;
}

@media (max-width: 768px) {
  .words-grid {
    grid-template-columns: 1fr;
    gap: 0.85rem;
  }
}

/* Word Card */
.word-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  min-width: 0;
  word-break: break-word;
}

.word-card:hover {
  box-shadow: var(--shadow-md);
  border-color: rgba(59, 130, 246, 0.4);
  transform: translateY(-2px);
}

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  gap: 0.5rem;
}

.word-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.word-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--loan-word-text);
  letter-spacing: -0.3px;
  word-break: break-word;
}

.page-badge {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.card-tools {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.05rem;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  line-height: 1;
}

.icon-btn:hover {
  color: var(--primary);
  background: var(--bg-tertiary);
}

.icon-btn.active {
  color: #f59e0b;
}

/* Equivalents / Sareh List */
.equivalents-container {
  margin-top: 0.5rem;
  flex: 1;
}

.eq-label {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.eq-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.eq-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--sareh-bg);
  color: var(--sareh-text);
  border: 1px solid var(--sareh-border);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.eq-chip:hover {
  background: var(--sareh-chip-hover);
  transform: scale(1.02);
  box-shadow: 0 2px 4px rgba(4, 120, 87, 0.15);
}

.source-tag {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--primary);
  background: rgba(59, 130, 246, 0.12);
  padding: 0.1rem 0.35rem;
  border-radius: var(--radius-sm);
}

/* Card Footer / Raw def */
.card-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border-color);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.raw-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-family);
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: var(--transition);
}

.raw-toggle-btn:hover {
  color: var(--primary);
}

.raw-def-content {
  margin-top: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* Search Highlights */
mark.highlight {
  background-color: #fef08a;
  color: #854d0e;
  border-radius: 2px;
  padding: 0 2px;
}

body.dark mark.highlight {
  background-color: #713f12;
  color: #fef08a;
}

/* Loading & Empty States */
.loading-state, .empty-state {
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-muted);
}

.spinner {
  width: 44px;
  height: 44px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1.25rem;
}

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

.empty-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
}

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

.empty-state p {
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

/* Pagination */
.pagination-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 2.5rem;
  flex-wrap: wrap;
}

.btn-page {
  min-width: 38px;
  height: 38px;
  padding: 0 0.5rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.88rem;
}

.page-numbers {
  display: flex;
  gap: 0.35rem;
  align-items: center;
}

.page-num {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.page-num:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.page-num.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.page-dots {
  padding: 0 0.4rem;
  color: var(--text-muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: slideUp 0.25s ease;
}

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

.random-modal-card {
  max-width: 520px;
}

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

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.modal-close-btn:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  background: var(--bg-tertiary);
  gap: 0.5rem;
}

.fav-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.fav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.fav-word {
  font-weight: 700;
  color: var(--loan-word-text);
  font-size: 1.05rem;
}

.fav-eqs {
  font-size: 0.85rem;
  color: var(--sareh-text);
  margin-top: 0.2rem;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1e293b;
  color: #ffffff;
  padding: 0.65rem 1.5rem;
  border-radius: var(--radius-full);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 300;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: auto;
}

.footer-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* -------------------------------------------------------------
   Scroll to Top Floating Button
   ------------------------------------------------------------- */
.scroll-top-btn {
  position: fixed;
  bottom: 2rem;
  left: 2rem;
  width: 44px;
  height: 44px;
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 99;
}

.scroll-top-btn.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-top-btn:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-xl);
}

.scroll-top-btn:active {
  transform: scale(0.92);
}

/* -------------------------------------------------------------
   Mobile & Tablet Responsiveness (@media)
   ------------------------------------------------------------- */

/* Tablet & Smaller Screens (<= 768px) */
@media (max-width: 768px) {
  .container {
    padding: 0 1rem;
  }

  .main-content {
    padding-top: 1.25rem;
    padding-bottom: 2.5rem;
  }

  /* Alphabet Bar: Horizontal Touch Carousel */
  .alphabet-bar-container {
    position: relative;
    padding: 0 0.25rem;
  }

  .alphabet-bar {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 0.35rem 0.25rem 0.75rem;
    gap: 0.35rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
  }

  .alphabet-bar::-webkit-scrollbar {
    display: none; /* WebKit */
  }

  .alpha-btn {
    flex: 0 0 auto;
    min-width: 36px;
    height: 36px;
    padding: 0 0.55rem;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
  }

  /* Results Bar */
  .results-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    margin-bottom: 1rem;
    padding-bottom: 0.85rem;
  }

  .results-info {
    justify-content: space-between;
    width: 100%;
    font-size: 0.88rem;
  }

  .results-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
    width: 100%;
  }

  .source-filter, .sort-filter {
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
    font-size: 0.78rem;
  }

  .source-filter select, .sort-filter select {
    width: 100%;
    height: 40px;
    font-size: 16px; /* Prevents auto-zoom in iOS Safari */
    padding: 0.45rem 0.65rem;
  }

  #exportBtn {
    grid-column: 1 / -1;
    width: 100%;
    height: 38px;
    font-size: 0.85rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
  }

  /* Word Card Touch Adjustments */
  .word-card {
    padding: 1rem;
    border-radius: var(--radius-md);
  }

  .word-title {
    font-size: 1.15rem;
  }

  .icon-btn {
    min-width: 38px;
    min-height: 38px;
    font-size: 1.15rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .eq-chips {
    gap: 0.4rem;
  }

  .eq-chip {
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
  }

  .eq-chip:active {
    transform: scale(0.96);
  }

  .raw-toggle-btn {
    min-height: 34px;
    font-size: 0.78rem;
  }
}

/* Mobile Screens (<= 640px) */
@media (max-width: 640px) {
  .container {
    padding: 0 0.85rem;
  }

  /* Header */
  .header-container {
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    gap: 0.5rem;
  }

  .logo-area {
    gap: 0.55rem;
    min-width: 0;
  }

  .logo-icon {
    font-size: 1.6rem;
    flex-shrink: 0;
  }

  .logo-title {
    font-size: 1.05rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .logo-subtitle {
    display: none; /* Hide subtitle on mobile phones to free space */
  }

  .header-actions {
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .header-actions .btn-text {
    display: none; /* Turn header buttons into icon-only buttons on mobile */
  }

  .header-actions .btn-outline {
    padding: 0.45rem 0.65rem;
    min-height: 38px;
    border-radius: var(--radius-md);
  }

  .btn-icon {
    width: 38px;
    height: 38px;
  }

  /* Hero Section */
  .hero-section {
    padding: 1.25rem 0 0.85rem;
  }

  .stats-badge {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    margin-bottom: 0.85rem;
  }

  .search-box-wrapper {
    margin-bottom: 0.85rem;
  }

  .search-input-box {
    border-radius: var(--radius-md);
  }

  .search-icon {
    font-size: 1.1rem;
    padding: 0 0.65rem;
  }

  #searchInput {
    padding: 0.75rem 0;
    font-size: 16px; /* Prevents auto-zoom in iOS Safari */
  }

  #searchInput::placeholder {
    font-size: 0.85rem;
  }

  .clear-btn {
    padding: 0 0.75rem;
    font-size: 1.1rem;
    min-width: 38px;
    min-height: 38px;
  }

  /* Search Mode Tabs */
  .search-modes {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.35rem;
    margin-top: 0.65rem;
    width: 100%;
  }

  .mode-tab {
    padding: 0.45rem 0.25rem;
    font-size: 0.74rem;
    justify-content: center;
    border-radius: var(--radius-md);
    white-space: nowrap;
  }

  .mode-tab span {
    font-size: 0.82rem;
  }

  /* Pagination */
  .pagination-container {
    gap: 0.3rem;
    margin-top: 1.5rem;
    justify-content: center;
  }

  .btn-page {
    height: 36px;
    padding: 0 0.65rem;
    font-size: 0.8rem;
  }

  .page-numbers {
    gap: 0.25rem;
  }

  .page-num {
    width: 34px;
    height: 34px;
    font-size: 0.82rem;
    border-radius: var(--radius-sm);
  }

  .page-dots {
    padding: 0 0.15rem;
    font-size: 0.8rem;
  }

  /* Modals: Bottom-Sheet Drawer Style */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end; /* Slide up as bottom sheet on mobile */
  }

  .modal-card {
    max-width: 100%;
    max-height: 88vh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-top-left-radius: var(--radius-lg);
    border-top-right-radius: var(--radius-lg);
    animation: sheetSlideUp 0.25s ease-out;
  }

  @keyframes sheetSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }

  .modal-header {
    padding: 1rem 1.25rem;
  }

  .modal-title {
    font-size: 1.05rem;
  }

  .modal-close-btn {
    min-width: 36px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
  }

  .modal-body {
    padding: 1rem;
    max-height: calc(88vh - 120px);
  }

  .modal-footer {
    padding: 0.85rem 1rem;
    flex-direction: column-reverse;
    gap: 0.5rem;
  }

  .modal-footer .btn {
    width: 100%;
    padding: 0.65rem;
    font-size: 0.88rem;
  }

  .fav-item {
    padding: 0.75rem;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .fav-item .card-tools {
    align-self: flex-end;
  }

  /* Scroll To Top Button */
  .scroll-top-btn {
    bottom: 1.25rem;
    left: 1.25rem;
    width: 40px;
    height: 40px;
    font-size: 1.15rem;
  }

  /* Toast */
  .toast {
    bottom: 1.25rem;
    padding: 0.55rem 1.1rem;
    font-size: 0.82rem;
    max-width: 90vw;
    text-align: center;
  }

  /* Footer */
  .footer {
    padding: 1.25rem 0;
    font-size: 0.78rem;
  }

  .footer-sub {
    font-size: 0.72rem;
  }
}

/* Extra Small Screens (<= 380px) */
@media (max-width: 380px) {
  .header-container {
    gap: 0.35rem;
  }

  .logo-title {
    font-size: 0.95rem;
  }

  .mode-tab {
    font-size: 0.68rem;
    padding: 0.35rem 0.15rem;
  }

  .mode-tab span {
    font-size: 0.75rem;
  }

  .btn-page {
    padding: 0 0.45rem;
    font-size: 0.75rem;
  }

  .page-num {
    width: 30px;
    height: 30px;
    font-size: 0.78rem;
  }
}
