/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1c24;
  --bg-tertiary: #242630;
  --bg-hover: #2d2f3a;
  --border: #363842;
  --border-active: #6c5ce7;
  --text-primary: #e8e8ec;
  --text-secondary: #9999a8;
  --text-muted: #666672;
  --accent: #6c5ce7;
  --accent-hover: #7e70f0;
  --accent-glow: rgba(108, 92, 231, 0.25);
  --danger: #e74c3c;
  --success: #2ecc71;
  --radius: 10px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
  --max-width: 640px;
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}

/* ===== Accessibility ===== */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  z-index: 1000;
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 1rem;
}

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

/* ===== Focus Styles ===== */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== Layout ===== */
header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}

h1 {
  font-size: clamp(1.5rem, 5vw, 2.25rem);
  font-weight: 700;
  background: linear-gradient(135deg, #6c5ce7, #a29bfe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.375rem;
}

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

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

/* ===== Upload Zone ===== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  transition: border-color var(--transition), background var(--transition);
  margin-bottom: 1.5rem;
}

.upload-zone:hover,
.upload-zone.drag-over {
  border-color: var(--accent);
  background: rgba(108, 92, 231, 0.05);
}

.upload-zone.drag-over {
  box-shadow: 0 0 24px var(--accent-glow);
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  cursor: pointer;
  min-height: 180px;
}

.upload-icon {
  color: var(--text-muted);
  margin-bottom: 1rem;
  width: 48px;
  height: 48px;
}

.upload-zone:hover .upload-icon,
.upload-zone.drag-over .upload-icon {
  color: var(--accent);
}

.upload-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.upload-subtext {
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.browse-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.browse-link:hover {
  color: var(--accent-hover);
}

.upload-hint {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 0.75rem;
}

/* ===== Quality Slider ===== */
#quality-section {
  margin-bottom: 1.5rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
}

.quality-label {
  display: block;
  font-size: 0.9375rem;
  margin-bottom: 0.75rem;
  color: var(--text-secondary);
}

.quality-label strong {
  color: var(--accent);
  font-size: 1.125rem;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 0 8px var(--accent-glow);
  transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.quality-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.375rem;
}

/* ===== Preview Grid ===== */
#preview-section {
  margin-bottom: 1.5rem;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}

.preview-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  position: relative;
  transition: border-color var(--transition);
}

.preview-card:hover {
  border-color: var(--accent);
}

/* Checkerboard transparency preview */
.preview-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background-image:
    linear-gradient(45deg, #1e2028 25%, transparent 25%),
    linear-gradient(-45deg, #1e2028 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1e2028 75%),
    linear-gradient(-45deg, transparent 75%, #1e2028 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0px;
  background-color: #16181f;
  display: block;
}

.preview-info {
  padding: 0.5rem 0.625rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.25rem;
}

.preview-name {
  font-size: 0.6875rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.preview-size {
  font-size: 0.6875rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

.preview-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  font-size: 1rem;
  flex-shrink: 0;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}

.preview-remove:hover,
.preview-remove:focus-visible {
  color: var(--danger);
  background: rgba(231, 76, 60, 0.12);
}

.preview-card.converted {
  border-color: var(--success);
}

.preview-card.converted::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  background: var(--success);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

/* ===== Buttons ===== */
#actions-section {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.btn {
  flex: 1;
  padding: 0.875rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ===== Progress ===== */
.progress-bar-wrapper {
  width: 100%;
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #a29bfe);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  text-align: center;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ===== Error Display ===== */
.error-display {
  background: rgba(231, 76, 60, 0.1);
  border: 1px solid rgba(231, 76, 60, 0.3);
  color: #f5a5a5;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
  text-align: center;
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Mobile ===== */
@media (max-width: 480px) {
  header {
    padding: 1.5rem 1rem 0.75rem;
  }

  .upload-content {
    padding: 2rem 1rem;
    min-height: 150px;
  }

  .preview-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }

  #actions-section {
    flex-direction: column;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
