:root {
  --background-color: #f5f5f5;
  --text-color: #333;
  --heading-color: #2c3e50;
  --box-background: rgba(255, 255, 255, 0.9);
  --box-border: rgba(255, 255, 255, 0.2);
  --box-shadow: rgba(0, 0, 0, 0.1);
  --button-primary: #3498db;
  --button-primary-hover: #2980b9;
  --button-success: #2ecc71;
  --button-success-hover: #27ae60;
  --button-danger: #e74c3c;
  --button-danger-hover: #c0392b;
  --button-disabled: #95a5a6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background-color: #1a1a1a;
    --text-color: #e0e0e0;
    --heading-color: #b0c4de;
    --box-background: rgba(30, 30, 30, 0.9);
    --box-border: rgba(70, 70, 70, 0.2);
    --box-shadow: rgba(0, 0, 0, 0.3);
    --button-primary: #2980b9;
    --button-primary-hover: #3498db;
    --button-success: #27ae60;
    --button-success-hover: #2ecc71;
    --button-danger: #c0392b;
    --button-danger-hover: #e74c3c;
    --button-disabled: #4a5556;
  }
}

.description {
  background: var(--box-background);
  border: 1px solid var(--box-border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 2px 4px var(--box-shadow);
}

.description p {
  margin-bottom: 1rem;
  text-align: center;
}

.changelog {
  margin-top: 0.5rem;
}

.changelog summary {
  cursor: pointer;
  padding: 0.5rem;
  background: var(--box-border);
  border-radius: 4px;
  text-align: center;
  transition: background-color 0.3s ease;
}

.changelog summary:hover {
  background: var(--button-primary);
  color: white;
}

.changelog ul {
  margin-top: 1rem;
  padding-left: 1.5rem;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 1rem;
}

.changelog li {
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

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

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

.container {
  max-width: 100%;
  margin: 0 auto;
  padding: 10px;
}

@media (min-width: 768px) {
  .container {
    max-width: 1200px;
    padding: 20px;
  }
}

.slider-controls,
.original-image,
.processed-image,
.color-layer {
  background: var(--box-background);
  border: 1px solid var(--box-border);
  width: 100%;
}

h1 {
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--heading-color);
  font-size: 1.5rem;
  background: var(--box-background);
  padding: 0.8rem;
  border-radius: 8px;
}

@media (min-width: 768px) {
  h1 {
    font-size: 2rem;
    padding: 1rem;
  }
}

.upload-section {
  text-align: center;
  margin-bottom: 1.5rem;
}

.slider-controls {
  text-align: center;
  margin: 1rem 0;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 4px var(--box-shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  position: static;
  margin-bottom: 1.5rem;
}

@media (min-width: 1024px) {
  .slider-controls {
    position: sticky;
    top: 1rem;
  }
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  justify-content: center;
  flex-wrap: wrap;
}

.slider-group label {
  min-width: 100px;
  text-align: right;
}

.slider-group input[type="range"] {
  flex: 1;
  min-width: 150px;
  max-width: 200px;
  height: 30px;
}

.slider-group span {
  min-width: 60px;
  text-align: left;
}

.upload-button {
  display: inline-flex;
  padding: 12px 24px;
  background: var(--button-primary);
  color: white;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s ease;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

.preview-section {
  display: none;
  gap: 1rem;
  order: 2;
}

.preview-section.visible {
  display: grid;
}

@media (min-width: 768px) {
  .preview-section.visible {
    grid-template-columns: 1fr 1fr;
    order: 1;
  }
}

.original-image, .processed-image {
  flex: 1;
  min-width: 0;
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.original-image canvas, .processed-image canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
}

.color-layer {
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.color-layer canvas {
  max-width: 100%;
  height: auto !important;
  margin: 0.5rem 0;
}

.split-output {
  display: none;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.split-output.visible {
  display: grid;
}

@media (min-width: 768px) {
  .split-output.visible {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 1rem 0;
}

@media (min-width: 768px) {
  .controls {
    flex-direction: row;
    justify-content: center;
  }
}

button {
  width: 100%;
  padding: 12px 24px;
  font-size: 0.9rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.3s ease;
  background: var(--button-success);
  color: white;
  min-height: 44px;
}

@media (min-width: 768px) {
  button {
    width: auto;
  }
}

.reset-button {
  padding: 6px 12px;
  background: var(--button-danger);
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.5rem 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

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

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--button-disabled);
  transition: .4s;
  border-radius: 34px;
}

.switch .slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--button-success);
}

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

@media (max-width: 768px) {
  .toggle-group {
    justify-content: center;
    width: 100%;
  }
}

.dithering-selector {
  width: 100%;
  margin-bottom: 1rem;
}

.dithering-selector summary {
  cursor: pointer;
  padding: 0.5rem;
  background: var(--box-border);
  border-radius: 4px;
  text-align: center;
  transition: background-color 0.3s ease;
}

.dithering-selector summary:hover {
  background: var(--button-primary);
  color: white;
}

.dithering-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.5rem;
}

.dithering-options label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 4px;
  transition: background-color 0.3s ease;
}

.dithering-options label:hover {
  background: var(--box-border);
}

.dithering-options input[type="radio"] {
  margin: 0;
}

@media (min-width: 768px) {
  .dithering-options {
    flex-direction: row;
    justify-content: center;
    gap: 2rem;
  }
}

.main-content {
  display: grid;
  gap: 1rem;
  margin: 1.5rem 0;
}

@media (min-width: 1024px) {
  .main-content {
    grid-template-columns: 300px 1fr;
    gap: 2rem;
  }
}

/* On mobile, controls come first, then images */
.controls-sidebar {
  order: 1;
}

@media (min-width: 1024px) {
  .controls-sidebar {
    order: 2;
  }
}

.download-controls {
  display: none;
  width: 100%;
  flex-direction: column;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
}

.download-controls.visible {
  display: flex;
}

@media (min-width: 768px) {
  .download-controls.visible {
    flex-direction: row;
  }
}

#imageInput {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.scaling-toggle {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.5rem 0;
  justify-content: center;
}

.scaling-toggle label {
  cursor: pointer;
}

.color-count {
  text-align: center;
  padding: 0.5rem 1rem;
  background: var(--box-background);
  border: 1px solid var(--box-border);
  border-radius: 8px;
  margin-bottom: 1rem;
  font-weight: bold;
  color: var(--heading-color);
}