:root {
  color-scheme: dark;
  --bg-color: #05050a;
  --card-bg: rgba(15, 17, 26, 0.65);
  --card-border: rgba(255, 255, 255, 0.08);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-1: #8b5cf6;
  --accent-2: #3b82f6;
  --accent-3: #ec4899;
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --success: #10b981;
  --input-bg: rgba(0, 0, 0, 0.4);
  --input-border: rgba(255, 255, 255, 0.12);
  --input-focus: rgba(139, 92, 246, 0.5);
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Playful, premium background blobs */
.bg-gradient {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  pointer-events: none;
  background: var(--bg-color);
  overflow: hidden;
}

.blob {
  position: absolute;
  filter: blur(80px);
  opacity: 0.4;
  border-radius: 50%;
  animation: float 10s infinite alternate ease-in-out;
}

.blob-1 {
  top: -10%; left: -10%; width: 50vw; height: 50vw; background: var(--accent-1);
}
.blob-2 {
  bottom: -10%; right: -10%; width: 60vw; height: 60vw; background: var(--accent-2); animation-delay: -5s;
}
.blob-3 {
  top: 40%; left: 60%; width: 40vw; height: 40vw; background: var(--accent-3); animation-delay: -2s; opacity: 0.2;
}

@keyframes float {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(5%, 5%) scale(1.1); }
}

.container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 3rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

h1 {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, #fff 20%, #a5b4fc 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero p {
  font-size: 1.125rem;
  color: var(--text-secondary);
  max-width: 450px;
  line-height: 1.5;
}

.content-grid {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255,255,255,0.1);
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-bottom: 1.5rem;
}

.input-group label {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-left: 0.25rem;
}

.input-wrapper, .select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-icon {
  position: absolute;
  left: 1.25rem;
  color: var(--text-secondary);
  pointer-events: none;
  transition: color var(--transition);
}

input, textarea, select {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  transition: var(--transition);
  outline: none;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

input::placeholder, textarea::placeholder {
  color: var(--text-secondary);
  opacity: 0.7;
}

input, select {
  height: 3.5rem;
}

input {
  padding: 0 1rem 0 3rem;
}

textarea {
  padding: 1.25rem;
  resize: vertical;
  min-height: 7rem;
  line-height: 1.5;
}

select {
  padding: 0 3rem 0 1.25rem;
  appearance: none;
  cursor: pointer;
}

.select-arrow {
  position: absolute;
  right: 1.25rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent-1);
  box-shadow: 0 0 0 4px var(--input-focus), inset 0 2px 4px rgba(0,0,0,0.1);
  background: rgba(0, 0, 0, 0.6);
}

input:focus + .input-icon,
.input-wrapper:has(input:focus) .input-icon {
  color: var(--accent-1);
}

/* Accessibility visible focus globally */
:focus-visible {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
}
input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: none; /* Managed by box-shadow */
}

/* Input Error State */
.input-error {
  border-color: var(--error) !important;
  box-shadow: 0 0 0 4px var(--error-bg) !important;
  animation: shake 0.4s cubic-bezier(0.36, 0.07, 0.19, 0.97) both;
}

.error-message {
  color: var(--error);
  font-size: 0.875rem;
  font-weight: 500;
  margin-left: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  animation: fadeIn 0.3s ease;
}

.error-message::before {
  content: "!";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.25rem;
  height: 1.25rem;
  background: var(--error-bg);
  border-radius: 50%;
  font-weight: bold;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.btn-primary {
  width: 100%;
  height: 3.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.125rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s, filter 0.2s;
  position: relative;
  overflow: hidden;
  box-shadow: 0 8px 20px -6px rgba(139, 92, 246, 0.6);
}

.btn-primary::before {
  content: "";
  position: absolute;
  top: 0; left: -100%; width: 50%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transform: skewX(-20deg);
  transition: 0.5s;
}

.btn-primary:hover:not(:disabled)::before {
  left: 150%;
}

.btn-primary:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -8px rgba(139, 92, 246, 0.7);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 4px 12px -4px rgba(139, 92, 246, 0.6);
}

.btn-primary:disabled {
  opacity: 0.8;
  cursor: not-allowed;
  filter: grayscale(0.6);
}

.spinner {
  display: none;
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: spin 0.8s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.btn-primary.loading .btn-text,
.btn-primary.loading .btn-icon {
  display: none;
}

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

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

.status-container {
  margin-top: 1.5rem;
  padding: 1rem;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.9375rem;
  font-weight: 500;
  animation: slideDown 0.3s ease;
  line-height: 1.5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

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

.status-container.success {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-container.success::before {
  content: "✓";
  font-weight: bold;
}

.status-container.error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-container.error::before {
  content: "✕";
  font-weight: bold;
}

.status-container.loading {
  background: rgba(59, 130, 246, 0.1);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.result-section {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.image-wrapper {
  width: 100%;
  min-height: 250px;
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Skeleton loader for image */
.image-loader {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(255,255,255,0.02);
}

.shimmer {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.05), transparent);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.image-wrapper img {
  width: 100%;
  height: auto;
  display: block;
  object-fit: contain;
  transition: opacity 0.4s ease;
}

.image-wrapper img.loading-opacity {
  opacity: 0;
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  width: 100%;
  height: 3.75rem;
  background: rgba(255, 255, 255, 0.05);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  font-size: 1.0625rem;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(1px);
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

/* Mobile optimizations */
@media (max-width: 640px) {
  .controls-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
  
  .card {
    padding: 1.5rem;
    border-radius: var(--radius-md);
  }
  
  .container {
    padding: 1.5rem 1rem;
    gap: 1.5rem;
  }

  .hero {
    margin-top: 0.5rem;
  }
  
  h1 {
    font-size: 2.25rem;
  }
  
  .btn-primary, .btn-secondary, input, select {
    height: 3.5rem;
  }
}