:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --text: #1f2937;
  --text-light: #6b7280;
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --border: #e5e7eb;
  --code-bg: #1e293b;
  --code-text: #e2e8f0;
  --blockquote-bg: #f8fafc;
  --blockquote-border: #2563eb;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --transition: all 0.2s ease-in-out;
}

/* Typography */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Fira+Code&display=swap');

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.8;
  color: var(--text);
  background-color: var(--bg);
  margin: 0;
  padding: 0;
}

/* Layout */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

.header {
  text-align: center;
  margin-bottom: 3rem;
  padding: 2rem 0;
}

.header h1 {
  font-size: 2.5rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
  color: #111827;
}

.header p {
  font-size: 1.25rem;
  color: var(--text-light);
  margin: 0;
}

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

/* Search Form */
.search-form {
  max-width: 700px;
  margin: 0 auto 3rem;
}

.input-group {
  display: flex;
  box-shadow: var(--shadow);
  border-radius: 0.5rem;
  overflow: hidden;
  transition: var(--transition);
  border: 1px solid var(--border);
}

.input-group:focus-within {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

#topicInput {
  flex: 1;
  padding: 1rem 1.25rem;
  font-size: 1.1rem;
  border: none;
  outline: none;
  background-color: var(--card-bg);
  color: var(--text);
}

#generateBtn {
  background-color: var(--primary);
  color: white;
  border: none;
  padding: 0 2rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  min-width: 160px;
  position: relative;
  overflow: hidden;
}

#generateBtn:hover {
  background-color: var(--primary-dark);
}

#generateBtn:disabled {
  background-color: #93c5fd;
  cursor: not-allowed;
}

/* Spinner */
.spinner {
  display: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
  position: absolute;
}

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

/* Article Container */
.article-container {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
  max-width: 800px;
  margin: 0 auto;
}

.article-container.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Article Styling */
.article {
  background: var(--card-bg);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  padding: 3rem;
  margin-bottom: 2rem;
}

.article-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.article h1 {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1.2;
  margin: 0 0 1rem 0;
  color: #111827;
}

.article h2 {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 2.5rem 0 1.25rem 0;
  color: #1f2937;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.article h3 {
  font-size: 1.375rem;
  font-weight: 600;
  margin: 2rem 0 1rem 0;
  color: #374151;
}

.article p {
  margin: 1.5rem 0;
  font-size: 1.1rem;
  line-height: 1.8;
  color: #4b5563;
}

.article ul, 
.article ol {
  margin: 1.5rem 0;
  padding-left: 2rem;
}

.article li {
  margin-bottom: 0.75rem;
  line-height: 1.7;
  color: #4b5563;
}

.article a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s ease;
  word-break: break-word;
}

.article a:hover {
  color: var(--primary-dark);
  text-decoration: underline;
}

.article blockquote {
  margin: 2rem 0;
  padding: 1.5rem;
  border-left: 4px solid var(--blockquote-border);
  background-color: var(--blockquote-bg);
  border-radius: 0 0.5rem 0.5rem 0;
  font-style: italic;
  color: #4b5563;
  position: relative;
}

.article blockquote p {
  margin: 0;
}

.article img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin: 2rem 0;
  display: block;
}

.article pre {
  background-color: var(--code-bg);
  color: var(--code-text);
  padding: 1.5rem;
  border-radius: 0.5rem;
  overflow-x: auto;
  margin: 2rem 0;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 0.95rem;
  line-height: 1.6;
  tab-size: 2;
}

.article code {
  font-family: 'Fira Code', 'Courier New', monospace;
  background-color: #f3f4f6;
  padding: 0.2em 0.4em;
  border-radius: 0.25rem;
  font-size: 0.9em;
  color: #dc2626;
}

.article pre code {
  background-color: transparent;
  padding: 0;
  color: inherit;
  font-size: 1em;
}

/* Source Citations */
.source-citation {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.8em;
  vertical-align: super;
  margin: 0 2px;
  font-weight: 500;
  line-height: 1;
}

.sources-section {
  margin-top: 4rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
}

.sources-section h2 {
  font-size: 1.5rem;
  color: #111827;
  margin-bottom: 1.5rem;
  border: none;
  padding: 0;
}

.sources-list {
  list-style: none;
  padding: 0;
  margin: 0;
  counter-reset: source-counter;
}

.sources-list li {
  margin-bottom: 1rem;
  padding: 1.25rem;
  background-color: #f9fafb;
  border-radius: 0.5rem;
  border-left: 3px solid var(--primary);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  padding-left: 3rem;
  counter-increment: source-counter;
}

.sources-list li::before {
  content: counter(source-counter);
  position: absolute;
  left: 1rem;
  top: 1.25rem;
  background-color: var(--primary);
  color: white;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
}

.sources-list li:hover {
  transform: translateX(4px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sources-list a {
  color: #1e40af;
  text-decoration: none;
  display: block;
  word-break: break-all;
  font-size: 0.95rem;
}

.sources-list a:hover {
  text-decoration: underline;
}

/* Article Meta */
.article-meta {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-top: 1.5rem;
  font-size: 0.95rem;
  color: #6b7280;
}

.article-meta span {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.article-meta svg {
  width: 1.1rem;
  height: 1.1rem;
  color: #9ca3af;
}

/* Error Message */
.error-message {
  background-color: #fef2f2;
  color: #b91c1c;
  padding: 1.5rem;
  border-radius: 0.5rem;
  border-left: 4px solid #dc2626;
  margin: 1rem 0;
}

.error-message p {
  margin: 0;
  font-size: 1rem;
  line-height: 1.5;
}

/* Footer */
.footer {
  text-align: center;
  padding: 2rem 0;
  margin-top: 3rem;
  color: var(--text-light);
  font-size: 0.95rem;
  border-top: 1px solid var(--border);
}

.footer strong {
  color: var(--primary);
  font-weight: 600;
}

/* Loading State */
.loading #btnText {
  visibility: hidden;
  opacity: 0;
}

.loading #spinner {
  display: block;
}

/* Responsive Design */
@media (max-width: 768px) {
  .container {
    padding: 1.5rem 1rem;
  }
  
  .header h1 {
    font-size: 2rem;
  }
  
  .header p {
    font-size: 1.1rem;
  }
  
  .article {
    padding: 1.5rem;
  }
  
  .article h1 {
    font-size: 1.75rem;
  }
  
  .article h2 {
    font-size: 1.5rem;
  }
  
  .article h3 {
    font-size: 1.25rem;
  }
  
  .article p, 
  .article li {
    font-size: 1rem;
  }
  
  .input-group {
    flex-direction: column;
  }
  
  #topicInput {
    padding: 0.875rem 1rem;
    width: 100%;
  }
  
  #generateBtn {
    padding: 0.75rem;
    width: 100%;
  }
}

/* Smooth Scrolling */
html {
  scroll-behavior: smooth;
  scroll-padding-top: 2rem;
  height: 100%;
  font-size: 16px;
}

/* Selection */
::selection {
  background-color: rgba(37, 99, 235, 0.2);
  color: inherit;
}

/* Print Styles */
@media print {
  .search-form,
  .footer {
    display: none;
  }
  
  .article {
    padding: 0;
    box-shadow: none;
  }
  
  .article a {
    text-decoration: none;
    color: inherit;
  }
  
  .sources-list a::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: var(--text-light);
  }
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.5;
  color: var(--text-color);
  background-color: var(--bg-color);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 3rem;
}

.header h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text-color);
}

.header p {
  color: var(--text-light);
  font-size: 1.125rem;
}

/* Search Form */
.search-form {
  margin-bottom: 3rem;
  width: 100%;
}

.input-group {
  display: flex;
  box-shadow: var(--shadow);
  border-radius: 1rem;
  overflow: hidden;
  transition: var(--transition);
  border: 1px solid var(--border-color);
}

.input-group:focus-within {
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

#generateBtn:hover {
  background-color: #1d4ed8;
}

#generateBtn:disabled {
  background-color: #93c5fd;
  cursor: not-allowed;
}

/* Spinner */
.spinner {
  display: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 1s ease-in-out infinite;
  position: absolute;
}

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

/* Article Container */
.article-container {
  margin-top: 2rem;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
}

.article-container.visible {
  opacity: 1;
  transform: translateY(0);
}

.article {
  background-color: white;
  border-radius: 0.5rem;
  box-shadow: var(--shadow);
  padding: 2rem;
  margin-bottom: 2rem;
}

.article h2 {
  font-size: 1.75rem;
  margin-bottom: 1.5rem;
  color: var(--text-color);
  line-height: 1.2;
}

.article h3 {
  font-size: 1.25rem;
  margin: 1.5rem 0 1rem;
  color: var(--text-color);
}

.article p {
  margin-bottom: 1rem;
  color: var(--text-color);
  line-height: 1.7;
}

.article ul, .article ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}

.article li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

/* Error Message */
.error-message {
  text-align: center;
  padding: 3rem 1rem;
}

.error-message h2 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: var(--text-color);
}

.error-message p {
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

.btn {
  display: inline-block;
  background-color: var(--primary-color);
  color: white;
  padding: 0.625rem 1.25rem;
  border-radius: 0.375rem;
  text-decoration: none;
  font-weight: 500;
  transition: var(--transition);
}

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

/* Footer */
.footer {
  margin-top: auto;
  padding-top: 3rem;
  text-align: center;
  color: var(--text-light);
  font-size: 0.875rem;
}

/* Loading State */
.loading #btnText {
  visibility: hidden;
  opacity: 0;
}

.loading #spinner {
  display: block;
}

/* Responsive Design */
@media (max-width: 640px) {
  .container {
    padding: 1.5rem 1rem;
  }
  
  .header h1 {
    font-size: 1.75rem;
  }
  
  .input-group {
    flex-direction: column;
  }
  
  #topicInput {
    padding: 0.75rem 1rem;
  }
  
  #generateBtn {
    padding: 0.75rem;
    width: 100%;
  }
  
  .article {
    padding: 1.5rem 1rem;
  }
  
  .article h2 {
    font-size: 1.5rem;
  }
}

/* Source Citations */
.source-citation {
  color: #2563eb;
  text-decoration: none;
  font-size: 0.8em;
  vertical-align: super;
  margin: 0 2px;
}

.sources-section {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e7eb;
}

.sources-list {
  margin-top: 1rem;
  padding-left: 1.5rem;
}

.sources-list li {
  margin-bottom: 0.5rem;
  line-height: 1.6;
}

.sources-list a {
  color: #2563eb;
  text-decoration: none;
}

.sources-list a:hover {
  text-decoration: underline;
}