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

:root {
  --primary-color: #3b82f6;
  --primary-light: #60a5fa;
  --primary-dark: #1e40af;
  --secondary-color: #8b5cf6;
  --success-color: #10b981;
  --error-color: #ef4444;
  --warning-color: #f59e0b;
  --bg-color: #f0f4f8;
  --card-bg: #ffffff;
  --border-color: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.12);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.container {
  width: 100%;
  max-width: 1000px;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: containerSlideIn 0.5s ease-out;
}

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

.header {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
  color: white;
  padding: 32px 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.header::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 300px;
  height: 300px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

.header::after {
  content: '';
  position: absolute;
  bottom: -30%;
  left: -5%;
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}

.header h1 {
  font-size: 2.2rem;
  margin-bottom: 8px;
  font-weight: 800;
  letter-spacing: -0.5px;
  position: relative;
  z-index: 1;
}

.subtitle {
  font-size: 0.95rem;
  opacity: 0.95;
  position: relative;
  z-index: 1;
  font-weight: 500;
}

.main-content {
  padding: 32px 40px;
}

.input-section {
  margin-bottom: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
  color: var(--text-primary);
  font-size: 1rem;
  letter-spacing: 0.3px;
}

.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  transition: all 0.3s ease;
  background: #fafbfc;
  color: var(--text-primary);
  line-height: 1.5;
}

.form-group textarea::placeholder {
  color: var(--text-tertiary);
}

.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  background: white;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.form-group small {
  display: block;
  margin-top: 8px;
  color: var(--text-tertiary);
  font-size: 0.875rem;
  font-weight: 500;
}

.btn {
  padding: 14px 28px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: 0.3px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
  color: white;
  width: 100%;
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--text-secondary);
  color: white;
  box-shadow: var(--shadow-md);
}

.btn-secondary:hover {
  background: var(--text-primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.btn-loader {
  display: inline-block;
  animation: pulse 1.5s ease-in-out infinite;
}

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

.results-section {
  animation: slideIn 0.4s ease-out;
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 8px;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border-color);
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 10;
}

.results-header h2 {
  font-size: 1.2rem;
  color: var(--text-primary);
  font-weight: 800;
}

.results-content {
  display: grid;
  gap: 12px;
}

.metadata-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.metadata-item {
  background: linear-gradient(135deg, #f8fafc 0%, #f0f4f8 100%);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metadata-label {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.metadata-value {
  color: var(--text-primary);
  font-weight: 800;
  font-size: 0.85rem;
}

.matches-container {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  max-height: 45vh;
  overflow-y: auto;
  padding-right: 4px;
  padding-top: 4px;
}

.match-item {
  background: linear-gradient(135deg, #f8fafc 0%, #f0f4f8 100%);
  border-left: 3px solid var(--primary-color);
  padding: 10px;
  border-radius: 8px;
  transition: all 0.3s ease;
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.match-item:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--primary-light);
}

.match-code {
  font-family: 'Fira Code', 'Courier New', monospace;
  font-weight: 700;
  color: var(--primary-color);
  font-size: 0.9rem;
  letter-spacing: 0.5px;
}

.match-title {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.8rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.match-confidence {
  display: inline-block;
  background: linear-gradient(135deg, var(--success-color) 0%, #059669 100%);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(16, 185, 129, 0.25);
  align-self: flex-start;
  margin-top: 2px;
}

.error-section {
  animation: slideIn 0.4s ease-out;
}

.error-message {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  border-left: 5px solid var(--error-color);
  color: #7f1d1d;
  padding: 20px;
  border-radius: 12px;
  margin-bottom: 20px;
  font-weight: 600;
  border: 1px solid #fca5a5;
}

.footer {
  background: var(--bg-color);
  padding: 16px 40px;
  text-align: center;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
}

.footer a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 700;
  transition: color 0.3s ease;
}

.footer a:hover {
  color: var(--primary-dark);
}

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

@media (max-width: 768px) {
  .header {
    padding: 24px 20px;
  }

  .header h1 {
    font-size: 1.6rem;
  }

  .subtitle {
    font-size: 0.9rem;
  }

  .main-content {
    padding: 24px 20px;
  }

  .results-header {
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }

  .btn-secondary {
    width: 100%;
  }

  .match-item {
    padding: 16px;
  }

  .metadata-container {
    padding: 20px;
  }

  .metadata-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .container {
    border-radius: 12px;
  }

  .header {
    padding: 20px 16px;
  }

  .header h1 {
    font-size: 1.4rem;
  }

  .main-content {
    padding: 20px 16px;
  }

  .btn {
    padding: 12px 20px;
    font-size: 0.95rem;
  }

  .metadata-container {
    grid-template-columns: 1fr;
  }

  .matches-container {
    max-height: 250px;
  }
}
