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

:root {
  --primary: #6b4c8a;
  --primary-light: #9b7db8;
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #2c2c2c;
  --text-muted: #777;
  --border: #ddd;
  --radius: 8px;
}

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

header {
  background: var(--primary);
  color: white;
  padding: 1rem 2rem;
  text-align: center;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.hidden {
  display: none !important;
}

/* Upload */
#drop-zone {
  border: 2px dashed var(--primary-light);
  border-radius: var(--radius);
  padding: 3rem;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

#drop-zone:hover,
#drop-zone.dragover {
  background: #f0eaf5;
  border-color: var(--primary);
}

#drop-zone p {
  font-size: 1.1rem;
  color: var(--text-muted);
}

#drop-zone .subtle {
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.browse-btn {
  display: inline-block;
  margin-top: 0.5rem;
  padding: 0.5rem 1.5rem;
  background: var(--primary);
  color: white;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.95rem;
  transition: background 0.2s;
}

.browse-btn:hover {
  background: var(--primary-light);
}

/* Settings */
.settings-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.setting {
  flex: 1 1 200px;
}

.setting label {
  display: block;
  margin-bottom: 0.35rem;
  font-weight: 500;
  font-size: 0.9rem;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.color-count-btns {
  display: flex;
  gap: 0.5rem;
}

.color-count-btn {
  width: 2.5rem;
  height: 2.5rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.color-count-btn.active {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

#color-pickers {
  display: flex;
  gap: 0.5rem;
}

.color-picker {
  width: 3rem;
  height: 2.5rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 2px;
}

#dither-toggle {
  accent-color: var(--primary);
  margin-right: 0.3rem;
}

#generate-btn {
  display: block;
  width: 100%;
  padding: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

#generate-btn:hover {
  background: var(--primary-light);
}

/* Preview */
.preview-columns {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.preview-col {
  flex: 1 1 300px;
  min-width: 0;
}

.preview-col h3 {
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: var(--text-muted);
}

#original-canvas {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chart-col {
  flex: 2 1 400px;
}

#chart-wrapper {
  overflow: scroll;
  max-height: 70vh;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  resize: both;
}

#chart-canvas {
  display: block;
  image-rendering: pixelated;
}

/* Instructions */
#instructions-toggle {
  background: none;
  border: none;
  font: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  width: 100%;
  text-align: left;
  padding: 0;
}

#instructions-toggle .arrow {
  font-size: 0.8rem;
  transition: transform 0.2s;
  display: inline-block;
}

#instructions-toggle.open .arrow {
  transform: rotate(180deg);
}

#instructions-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

#instructions-content.expanded {
  max-height: 2000px;
  overflow: auto;
}

#instructions-text {
  font-family: 'Courier New', monospace;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.8;
  padding: 1rem 0;
  white-space: pre-wrap;
}

/* Export */
#export-section {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

#download-chart,
#download-instructions {
  flex: 1 1 200px;
  padding: 0.75rem;
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
}

#download-chart:hover,
#download-instructions:hover {
  background: var(--primary);
  color: white;
}

/* Responsive */
@media (max-width: 600px) {
  main {
    padding: 1rem;
  }

  .preview-columns {
    flex-direction: column;
  }

  #drop-zone {
    padding: 2rem 1rem;
  }
}
