/* CSS Custom Properties for theming */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --success-color: #10b981;
  --error-color: #ef4444;
  --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);
  --radius: 0.5rem;
  --transition: all 0.2s ease-in-out;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --border-color: #475569;
  --accent-color: #60a5fa;
  --accent-hover: #3b82f6;
  --success-color: #34d399;
  --error-color: #f87171;
}

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
  transition: var(--transition);
  min-height: 100vh;
}

/* Container and layout */
.container {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  text-align: center;
  padding: 2rem 0;
  position: relative;
}

.title {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.logo {
  font-size: 2rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
  font-size: 1.25rem;
}

.theme-toggle:hover {
  background: var(--bg-tertiary);
  transform: scale(1.05);
}

.theme-toggle:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Main content */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Mode selector */
.mode-selector {
  display: flex;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 0.25rem;
  gap: 0.25rem;
}

.mode-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: calc(var(--radius) - 0.25rem);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-weight: 500;
}

.mode-btn.active {
  background: var(--accent-color);
  color: white;
  box-shadow: var(--shadow-sm);
}

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

.mode-btn:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Form styles */
.form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.label {
  font-weight: 600;
  color: var(--text-primary);
}

.input,
.textarea {
  padding: 0.75rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1rem;
  transition: var(--transition);
  resize: vertical;
}

.input:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

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

.submit-btn {
  padding: 0.875rem 2rem;
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.submit-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.submit-btn:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.loading-spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  display: none;
}

.submit-btn.loading .loading-spinner {
  display: block;
}

.submit-btn.loading .btn-text {
  display: none;
}

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

/* Result section */
.result-section {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border-color);
  display: none;
}

.result-section.show {
  display: block;
  animation: fadeIn 0.3s ease-in-out;
}

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

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

.result-title {
  font-size: 1.25rem;
  font-weight: 600;
}

.copy-btn {
  padding: 0.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}

.copy-btn:hover {
  background: var(--bg-tertiary);
  transform: scale(1.05);
}

.copy-btn:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

.result-textarea {
  width: 100%;
  min-height: 100px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 0.75rem;
  color: var(--text-primary);
  font-family: "Courier New", monospace;
  resize: vertical;
}

.result-stats {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Error message */
.error-message {
  background: var(--error-color);
  color: white;
  padding: 1rem;
  border-radius: var(--radius);
  display: none;
  animation: shake 0.5s ease-in-out;
}

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

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

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

/* Responsive design */
@media (max-width: 640px) {
  .container {
    padding: 0.5rem;
  }

  .title {
    font-size: 2rem;
  }

  .theme-toggle {
    position: static;
    margin: 1rem auto 0;
    display: block;
  }

  .header {
    padding: 1rem 0;
  }

  .mode-selector {
    flex-direction: column;
  }

  .result-header {
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --border-color: #000000;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3);
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Print styles */
@media print {
  .theme-toggle,
  .submit-btn,
  .copy-btn {
    display: none;
  }

  .container {
    max-width: none;
    padding: 0;
  }

  .result-section {
    display: block !important;
    box-shadow: none;
    border: 1px solid #000;
  }
}
