/* ================================
   CSS Variables & Theme
   ================================ */
:root {
  /* Light theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: #eff6ff;
  --success: #10b981;
  --warning: #f59e0b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --radius-sm: 0.375rem;
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border: #334155;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
  --accent-light: #1e3a5f;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ================================
   Header
   ================================ */
.header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.logo-icon {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--accent);
}

.logo-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

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

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

.about-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.about-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.about-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

.theme-toggle {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.theme-toggle svg {
  width: 1.25rem;
  height: 1.25rem;
}

.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* ================================
   Main Content
   ================================ */
.main {
  flex: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

/* Hero Section */
.hero {
  text-align: center;
  padding: 2.5rem 0 1.5rem;
}

.hero h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.hero p {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ================================
   Search Section
   ================================ */
.search-section {
  margin-bottom: 1.5rem;
}

.search-container {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.search-box {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  width: 1.25rem;
  height: 1.25rem;
  color: var(--text-muted);
  pointer-events: none;
}

#searchInput {
  width: 100%;
  padding: 0.875rem 2.75rem 0.875rem 3rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  transition: all 0.2s;
}

#searchInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

#searchInput::placeholder {
  color: var(--text-muted);
}

.search-clear {
  position: absolute;
  right: 0.75rem;
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
}

.search-clear:hover {
  background: var(--border);
  color: var(--text-primary);
}

.search-clear svg {
  width: 1rem;
  height: 1rem;
}

.search-clear.visible {
  display: flex;
}

.random-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.random-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.random-btn svg {
  width: 1.125rem;
  height: 1.125rem;
}

.search-stats {
  font-size: 0.875rem;
  color: var(--text-muted);
  min-height: 1.25rem;
}

/* ================================
   Alphabet Navigation
   ================================ */
.alphabet-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  justify-content: center;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.letter-btn {
  min-width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.letter-btn:hover:not(.disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  transform: translateY(-1px);
}

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

.letter-btn.disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.letter-btn.all-btn {
  min-width: 3.5rem;
  font-size: 0.8rem;
}

/* ================================
   Results Section
   ================================ */
.results-section {
  margin-bottom: 2rem;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}

.results-header h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
}

.results-count {
  font-size: 0.875rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
}

.results {
  display: grid;
  gap: 0.5rem;
}

/* Term Card */
.term-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}

.term-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.term-info {
  flex: 1;
  min-width: 0;
}

.term-name {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.125rem;
}

.term-name mark {
  background: var(--warning);
  color: var(--text-primary);
  padding: 0 0.125rem;
  border-radius: 2px;
}

.term-translation {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.term-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  flex-shrink: 0;
}

/* Letter Header */
.letter-header {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  padding: 1rem 0 0.5rem;
  margin-top: 0.5rem;
  border-bottom: 2px solid var(--accent);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.letter-header:first-child {
  margin-top: 0;
}

.letter-count {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
}

/* No Results */
.no-results {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.no-results svg {
  width: 4rem;
  height: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.no-results h3 {
  font-size: 1.125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.loading-spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 1rem;
}

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

/* ================================
   Modal
   ================================ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal.active {
  display: flex;
}

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

.modal-content {
  position: relative;
  background: var(--bg-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  animation: modalIn 0.2s ease-out;
}

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

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all 0.15s;
}

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

.modal-close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.modal-body {
  padding: 2rem;
}

.modal-term {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.modal-letter {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-light);
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}

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

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.modal-value {
  font-size: 1.125rem;
  color: var(--text-primary);
}

.modal-category {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* About Modal */
.about-content {
  max-width: 550px;
}

.about-header {
  text-align: center;
  margin-bottom: 2rem;
}

.about-icon {
  width: 3.5rem;
  height: 3.5rem;
  color: var(--accent);
  margin-bottom: 1rem;
}

.about-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

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

.about-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

.about-section p {
  font-size: 0.9375rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.about-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 2rem 0;
  padding: 1.5rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.stat-item {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

.about-footer {
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  margin-top: 1.5rem;
}

.about-footer p {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* ================================
   Footer
   ================================ */
.footer {
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  padding: 1.5rem;
  text-align: center;
}

.footer-content p {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.footer-stats {
  margin-top: 0.25rem;
  font-size: 0.8rem;
}

/* ================================
   Responsive
   ================================ */
@media (max-width: 640px) {
  .header-content {
    padding: 0.875rem 1rem;
  }

  .logo-text h1 {
    font-size: 1.1rem;
  }

  .about-btn span {
    display: none;
  }

  .about-btn {
    padding: 0.5rem;
    width: 2.5rem;
    height: 2.5rem;
    justify-content: center;
  }

  .main {
    padding: 0 1rem;
  }

  .hero {
    padding: 1.5rem 0 1rem;
  }

  .hero h2 {
    font-size: 1.25rem;
  }

  .search-container {
    flex-direction: column;
  }

  .random-btn {
    width: 100%;
    justify-content: center;
    padding: 0.75rem;
  }

  .alphabet-nav {
    padding: 0.75rem;
    gap: 0.25rem;
  }

  .letter-btn {
    min-width: 2rem;
    height: 2rem;
    font-size: 0.8rem;
  }

  .term-card {
    flex-direction: column;
    align-items: flex-start;
  }

  .term-badge {
    margin-top: 0.5rem;
  }

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

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