:root {
  --md-primary: #6750a4;
  --md-primary-light: #8b73ca;
  --md-primary-dark: #4f378b;
  --md-on-primary: #ffffff;
  --md-secondary: #9c27b0;
  --md-surface: #fffbff;
  --md-surface-container: #f3edf7; /* Used for modal background */
  --md-surface-variant: #e7e0ec; /* Used for slider track, disabled states */
  --md-on-surface: #1c1b1f;
  --md-on-surface-variant: #49454f; /* Used for labels, icons */
  --md-outline: #79747e; /* Used for input borders */
  --md-elevation-1: 0 1px 2px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.05);
  --md-elevation-2: 0 2px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.05);
  --md-elevation-3: 0 4px 8px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.05);
  --md-radius-small: 4px; /* M3 uses smaller radius */
  --md-radius-medium: 12px;
  --md-radius-large: 28px; /* For modal dialog */
  --md-radius-full: 999px; /* For slider thumb */
  --md-transition: all 0.2s ease-in-out; /* Slightly faster M3 transition */
  --md-slider-track-height: 4px;
  --md-slider-thumb-size: 20px;
  --md-slider-thumb-hover-size: 28px; /* Thumb halo */
  --md-slider-thumb-focus-size: 40px; /* Focus halo */
}

/* General Body Styles */
body {
  font-family: "Roboto", "Segoe UI", system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
  background-color: var(--md-surface);
  color: var(--md-on-surface);
  margin: 0;
  transition: var(--md-transition);
  max-width: 800px; /* Limit max width */
  margin: 0 auto;
}

h1,
h2 {
  color: var(--md-on-surface);
  font-weight: 400;
}

h1 {
  font-size: 28px; /* Slightly smaller h1 */
  margin-bottom: 0; /* Removed default margin */
}

h2 {
  font-size: 22px;
  margin-top: 32px;
  margin-bottom: 16px;
}

p {
  color: var(--md-on-surface-variant);
  margin-bottom: 24px;
  text-align: center;
  max-width: 600px;
}

/* Header Styles */
.app-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px; /* Adjust spacing */
}

/* Icon Button Styles (Used for Settings, Close, Reset) */
.md-icon-button,
.reset-button {
  background: none;
  border: none;
  padding: 8px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--md-on-surface-variant);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden; /* Needed for ripple */
  transition: background-color 0.15s ease-out;
  flex-shrink: 0; /* Prevent shrinking in flex layouts */
  width: 40px; /* M3 touch target size */
  height: 40px;
  box-sizing: border-box;
}

.md-icon-button:hover,
.reset-button:hover {
  background-color: rgba(0, 0, 0, 0.08); /* Use subtle hover */
}

.md-icon-button:active,
.reset-button:active {
  background-color: rgba(0, 0, 0, 0.12);
}

.md-icon-button .material-symbols-rounded,
.reset-button .material-symbols-rounded {
  font-size: 24px;
  display: block; /* Prevent extra space */
}

/* Drop Zone Styles */
#drop-zone {
  width: 100%;
  max-width: 100%;
  height: 250px; /* Slightly smaller */
  border: 2px dashed var(--md-outline);
  border-radius: var(--md-radius-medium); /* M3 medium radius */
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  color: var(--md-on-surface-variant);
  background-color: var(--md-surface-container);
  margin-bottom: 24px;
  transition: var(--md-transition);
  transition-property: border-color, transform, box-shadow, background-color;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.drop-icon {
  font-size: 48px;
  margin-bottom: 12px;
  color: var(--md-primary);
}

#drop-zone::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--md-primary);
  opacity: 0;
  transition: var(--md-transition);
  z-index: 1;
  pointer-events: none;
}

#drop-zone.dragover {
  border-color: var(--md-primary);
  background-color: #e8def8; /* Lighter purple on drag */
  /* transform: scale(1.01); No scale needed */
  box-shadow: var(--md-elevation-1);
}

#drop-zone.dragover::after {
  opacity: 0.05;
}

#drop-zone.clicked {
  transform: scale(0.99);
  transition: transform 0.1s ease-out;
}

#drop-zone p,
#drop-zone button {
  position: relative;
  z-index: 2;
  margin: 8px 0;
}
#drop-zone p {
  margin-bottom: 8px;
}

.paste-hint {
  font-size: 12px; /* Smaller hint */
  opacity: 0.8;
  margin-top: 8px;
  margin-bottom: 0;
}

/* Standard Button Style (Browse Files) */
.md-button {
  position: relative;
  padding: 10px 24px; /* M3 Button Padding */
  margin-top: 16px;
  cursor: pointer;
  background-color: var(--md-primary);
  color: var(--md-on-primary);
  border: none;
  border-radius: var(--md-radius-full); /* M3 uses full radius */
  font-size: 14px; /* M3 font size */
  font-weight: 500;
  text-transform: none; /* M3 often uses sentence case */
  letter-spacing: 0.1px;
  box-shadow: var(--md-elevation-1);
  transition: var(--md-transition);
  transition-property: background-color, box-shadow, transform;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px; /* M3 touch target */
}

.md-button:hover {
  background-color: var(--md-primary-light);
  box-shadow: var(--md-elevation-2);
}

.md-button:active {
  transform: scale(0.98); /* Subtle click feedback */
}

/* Ripple Animation */
.ripple {
  position: absolute;
  border-radius: 50%;
  transform: scale(0);
  animation: ripple 0.6s linear;
  pointer-events: none;
  /* Ripple color set in JS based on button type */
}

@keyframes ripple {
  to {
    transform: scale(2.5);
    opacity: 0;
  }
}

/* Status Indicator */
#status {
  width: 100%;
  max-width: 400px;
  margin-top: 20px;
  padding: 12px 16px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
  background-color: var(--md-surface-container);
  border-radius: var(--md-radius-medium);
  transition: var(--md-transition);
  box-shadow: var(--md-elevation-1);
  text-align: center;
  font-size: 14px;
}

#status.processing {
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(103, 80, 164, 0.3);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(103, 80, 164, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(103, 80, 164, 0);
  }
}

/* Preview Area */
#preview-canvas {
  margin-top: 16px;
  background-color: var(--md-surface-variant); /* Match background */
  border-radius: var(--md-radius-medium);
  max-width: 90%; /* Responsive width */
  height: auto; /* Maintain aspect ratio */
  box-shadow: var(--md-elevation-2);
  transition: opacity 0.3s ease-out, transform 0.3s ease-out;
  transform: translateY(10px) scale(0.98); /* Start slightly down and smaller */
  opacity: 0;
  display: block; /* Keep in layout flow even when hidden */
}

#preview-canvas.show {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.32);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0s linear 0.3s; /* Delay visibility change */
}

.modal-overlay.visible {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

.modal-dialog {
  background-color: var(--md-surface-container);
  color: var(--md-on-surface);
  border-radius: var(--md-radius-large);
  padding: 24px;
  box-shadow: var(--md-elevation-3);
  width: 90%;
  max-width: 400px;
  transform: scale(0.95) translateY(10px);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
}

.modal-overlay.visible .modal-dialog {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px; /* More space */
}

.modal-header h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 500;
}

.modal-content {
  display: flex;
  flex-direction: column;
  gap: 24px; /* Spacing between setting items */
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Container for label + value */
.slider-label-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px; /* Space between label and slider */
}

.setting-item label {
  font-size: 14px;
  font-weight: 500;
  color: var(--md-on-surface-variant);
}

.slider-value {
  font-size: 14px;
  font-weight: 400;
  color: var(--md-on-surface-variant);
}

.input-group {
  display: flex;
  align-items: center;
  gap: 12px; /* Space between input and reset button */
}

/* Basic Input Styles (for color picker) */
.setting-item input[type="color"] {
  flex-grow: 1;
  padding: 0; /* Remove padding for native picker */
  border: 1px solid var(--md-outline);
  border-radius: var(--md-radius-small);
  background-color: var(--md-surface);
  color: var(--md-on-surface);
  height: 40px; /* Match height roughly */
  cursor: pointer;
  min-width: 50px; /* Ensure it doesn't collapse */
}

.setting-item input[type="color"]:focus {
  outline: 2px solid var(--md-primary);
  outline-offset: 1px;
}

/* Number Input Styles */
.number-input {
  width: 80px;
  height: 40px;
  padding: 0 8px;
  border: 1px solid var(--md-outline);
  border-radius: var(--md-radius-small);
  background-color: var(--md-surface);
  color: var(--md-on-surface);
  font-size: 14px;
  text-align: center;
  margin-left: 8px;
}

.number-input:focus {
  outline: 2px solid var(--md-primary);
  outline-offset: 1px;
}

.number-input::-webkit-inner-spin-button,
.number-input::-webkit-outer-spin-button {
  opacity: 1;
  height: 24px;
}

/* Error Message Styles */
.error-message {
  color: #b00020; /* Material Design error color */
  font-size: 12px;
  margin-top: 4px;
  display: block; /* Use block for positioning */
  width: 100%; /* Span full width below input */
  text-align: right; /* Align error message relative to input group */
  padding-right: 50px; /* Adjust padding to align near the input */
}

/* Input Error State */
.number-input.error {
  border-color: #b00020;
}

.number-input.error:focus {
  outline-color: #b00020;
}

/* --- M3 Slider Styles --- */
.slider-container {
  gap: 16px; /* Space between slider and reset button */
}

input[type="range"] {
  flex-grow: 1;
  -webkit-appearance: none; /* Override default look */
  appearance: none;
  width: 100%; /* Full width */
  height: var(--md-slider-track-height);
  background: var(--md-surface-variant); /* Default track color */
  border-radius: var(--md-radius-full);
  outline: none;
  cursor: pointer;
  transition: background 0.1s ease-in-out; /* For dynamic track update */
  margin: calc(var(--md-slider-thumb-size) / 2) 0;
  /* Center thumb vertically */
}

/* Webkit (Chrome, Safari, Edge) Thumb */
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--md-slider-thumb-size);
  height: var(--md-slider-thumb-size);
  background: var(--md-primary);
  border-radius: var(--md-radius-full);
  border: none; /* No border needed */
  cursor: pointer;
  position: relative; /* For pseudo-elements */
  transition: background-color 0.15s ease-out, transform 0.15s ease-out,
    box-shadow 0.15s ease-out;
  box-shadow: var(--md-elevation-1); /* Subtle shadow */
}

/* Firefox Thumb */
input[type="range"]::-moz-range-thumb {
  width: var(--md-slider-thumb-size);
  height: var(--md-slider-thumb-size);
  background: var(--md-primary);
  border-radius: var(--md-radius-full);
  border: none;
  cursor: pointer;
  transition: background-color 0.15s ease-out, transform 0.15s ease-out,
    box-shadow 0.15s ease-out;
  box-shadow: var(--md-elevation-1);
}

/* Hover State - Add a "halo" effect */
input[type="range"]:hover::-webkit-slider-thumb::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: var(--md-slider-thumb-hover-size);
  height: var(--md-slider-thumb-hover-size);
  background-color: var(--md-primary);
  opacity: 0.12; /* M3 hover state opacity */
  border-radius: 50%;
  z-index: -1; /* Behind the thumb */
}
/* input[type="range"]:hover::-moz-range-thumb::before { */
/* Similar styling for Firefox if possible, often harder */
/* Consider just scaling thumb slightly or changing color */
/* } */

/* Active/Focus State - Larger halo */
input[type="range"]:active::-webkit-slider-thumb,
input[type="range"]:focus::-webkit-slider-thumb {
  background-color: var(--md-primary-dark); /* Darken thumb on active */
  transform: scale(1.1); /* Slightly enlarge thumb */
  box-shadow: var(--md-elevation-2);
}
input[type="range"]:active::-webkit-slider-thumb::before,
input[type="range"]:focus::-webkit-slider-thumb::before {
  width: var(--md-slider-thumb-focus-size);
  height: var(--md-slider-thumb-focus-size);
  opacity: 0.18; /* M3 focus state opacity */
}

input[type="range"]:active::-moz-range-thumb,
input[type="range"]:focus::-moz-range-thumb {
  background-color: var(--md-primary-dark);
  transform: scale(1.1);
  box-shadow: var(--md-elevation-2);
}

/* Webkit Track Styles (Less crucial with background gradient) */
input[type="range"]::-webkit-slider-runnable-track {
  width: 100%;
  cursor: pointer;
  background: transparent; /* Let the input element background handle it */
  border-radius: var(--md-radius-full);
}

/* Firefox Track Styles */
input[type="range"]::-moz-range-track {
  width: 100%;
  cursor: pointer;
  background: transparent; /* Let the input element background handle it */
  border-radius: var(--md-radius-full);
}

/* Toggle Switch Styles */
.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
  margin-left: auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--md-surface-variant);
  transition: .2s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
  box-shadow: var(--md-elevation-1);
}

input:checked + .slider {
  background-color: var(--md-primary);
}

input:checked + .slider:before {
  transform: translateX(24px);
}

/* Download Button Styles */
#download-button {
  display: none;
  margin-top: 16px;
  background-color: var(--md-primary);
  color: var(--md-on-primary);
  border: none;
  border-radius: var(--md-radius-full);
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--md-transition);
  box-shadow: var(--md-elevation-1);
}

#download-button:hover {
  background-color: var(--md-primary-light);
  box-shadow: var(--md-elevation-2);
}

#download-button:active {
  transform: scale(0.98);
}
