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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  min-height: 100vh;
  padding: 2rem;
  color: #1a202c;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  background: white;
  border-radius: 1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.header {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  padding: 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header h1 {
  font-size: 2rem;
  margin-bottom: 0.5rem;
}

.header p {
  opacity: 0.9;
  font-size: 1rem;
}

.header-actions {
  display: flex;
  gap: 1rem;
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
  color: #6366f1;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn.primary {
  background: #f59e0b;
  color: white;
}

section {
  padding: 2rem;
  border-bottom: 2px solid #f3f4f6;
}

section:last-of-type {
  border-bottom: none;
}

section h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  color: #1a202c;
}

.pattern-section label,
.test-section label,
.substitution-controls label {
  display: block;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.regex-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #1f2937;
  padding: 1rem;
  border-radius: 0.5rem;
  font-family: 'Courier New', monospace;
}

.regex-delimiter {
  color: #f59e0b;
  font-size: 1.5rem;
  font-weight: bold;
}

#pattern {
  flex: 1;
  background: transparent;
  border: none;
  color: #f9fafb;
  font-size: 1.25rem;
  font-family: 'Courier New', monospace;
  outline: none;
}

#pattern::placeholder {
  color: #6b7280;
}

.flags {
  display: flex;
  gap: 0.5rem;
  padding-left: 1rem;
  border-left: 2px solid #374151;
}

.flag-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.flag-label input {
  display: none;
}

.flag-label span {
  display: block;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #6b7280;
  border-radius: 0.25rem;
  color: #6b7280;
  font-weight: bold;
  transition: all 0.2s;
}

.flag-label input:checked + span {
  background: #f59e0b;
  border-color: #f59e0b;
  color: white;
}

.error-message {
  color: #dc2626;
  font-size: 0.875rem;
  margin-top: 0.5rem;
  font-family: 'Courier New', monospace;
  padding: 0.5rem;
  background: #fee2e2;
  border-radius: 0.25rem;
  display: none;
}

.error-message.visible {
  display: block;
}

.quick-patterns {
  margin-top: 1.5rem;
}

.quick-patterns label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 0.75rem;
}

.pattern-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pattern-btn {
  padding: 0.5rem 1rem;
  border: 2px solid #e5e7eb;
  background: white;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  transition: all 0.2s;
}

.pattern-btn:hover {
  border-color: #6366f1;
  color: #6366f1;
  background: #f3f4f6;
}

#testString {
  width: 100%;
  min-height: 200px;
  padding: 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  resize: vertical;
  line-height: 1.6;
}

#testString:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.match-info {
  margin-top: 1rem;
  padding: 1rem;
  background: #f3f4f6;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: #6b7280;
}

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

.match-count {
  background: #6366f1;
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
}

.highlighted-text {
  background: #1f2937;
  color: #f9fafb;
  padding: 1.5rem;
  border-radius: 0.5rem;
  font-family: 'Courier New', monospace;
  line-height: 1.8;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: 1.5rem;
  min-height: 100px;
  font-size: 0.95rem;
}

.match-highlight {
  background: #fbbf24;
  color: #1f2937;
  padding: 0.125rem 0.25rem;
  border-radius: 0.25rem;
  font-weight: bold;
}

.match-details {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.match-card {
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  padding: 1rem;
  background: #f9fafb;
}

.match-card-header {
  font-weight: 600;
  color: #6366f1;
  margin-bottom: 0.75rem;
  font-size: 0.875rem;
}

.match-value {
  font-family: 'Courier New', monospace;
  background: white;
  padding: 0.75rem;
  border-radius: 0.25rem;
  margin-bottom: 0.5rem;
  word-break: break-all;
}

.match-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.75rem;
  color: #6b7280;
}

.substitution-controls {
  margin-bottom: 1.5rem;
}

.control {
  margin-bottom: 1rem;
}

#replacement {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  font-family: 'Courier New', monospace;
  font-size: 1rem;
}

#replacement:focus {
  outline: none;
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.substitution-result {
  background: #f3f4f6;
  padding: 1.5rem;
  border-radius: 0.5rem;
}

.substitution-result label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: #374151;
}

#substitutionResult {
  background: #1f2937;
  color: #f9fafb;
  padding: 1rem;
  border-radius: 0.5rem;
  font-family: 'Courier New', monospace;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: 1rem;
  min-height: 60px;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.reference-card {
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  padding: 1.5rem;
  background: #f9fafb;
}

.reference-card h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: #6366f1;
}

.reference-card ul {
  list-style: none;
}

.reference-card li {
  padding: 0.5rem 0;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.875rem;
  color: #374151;
}

.reference-card li:last-child {
  border-bottom: none;
}

.reference-card code {
  background: #e5e7eb;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-family: 'Courier New', monospace;
  font-weight: bold;
  color: #dc2626;
  margin-right: 0.5rem;
}

.saved-patterns {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.saved-pattern {
  border: 2px solid #e5e7eb;
  border-radius: 0.5rem;
  padding: 1rem;
  background: #f9fafb;
  cursor: pointer;
  transition: all 0.2s;
}

.saved-pattern:hover {
  border-color: #6366f1;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.saved-pattern-name {
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #1a202c;
}

.saved-pattern-regex {
  font-family: 'Courier New', monospace;
  font-size: 0.875rem;
  color: #6b7280;
  margin-bottom: 0.5rem;
  word-break: break-all;
}

.saved-pattern-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.saved-pattern-btn {
  padding: 0.375rem 0.75rem;
  border: none;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.2s;
}

.saved-pattern-btn.load {
  background: #6366f1;
  color: white;
}

.saved-pattern-btn.delete {
  background: #dc2626;
  color: white;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: #6b7280;
}

.footer {
  text-align: center;
  padding: 1.5rem;
  color: white;
  font-size: 0.875rem;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

@media (max-width: 768px) {
  body {
    padding: 1rem;
  }

  .header {
    flex-direction: column;
    gap: 1rem;
    text-align: center;
  }

  .flags {
    flex-wrap: wrap;
  }

  .match-details,
  .reference-grid,
  .saved-patterns {
    grid-template-columns: 1fr;
  }
}
