* {
  box-sizing: border-box;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  margin: 0;
  padding: 0;
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 250px;
  background: #16162a;
  border-right: 1px solid #333;
  padding: 15px;
  overflow-y: auto;
  flex-shrink: 0;
}
.sidebar h2 {
  font-size: 14px;
  color: #888;
  margin: 0 0 15px 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #333;
}
.sidebar-logo img {
  border-radius: 8px;
  flex-shrink: 0;
}
.sidebar-logo span {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  line-height: 1.2;
}
.sidebar-empty {
  color: #555;
  font-size: 12px;
  text-align: center;
  padding: 20px 0;
}
.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: #2a2a4a;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}
.project-item:hover {
  background: #3a3a5a;
}
.project-item.active {
  background: #4a5a7a;
  border: 1px solid #6a7a9a;
}
.project-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  background: #fff;
  flex-shrink: 0;
}
.project-info {
  flex: 1;
  min-width: 0;
}
.project-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-date {
  font-size: 10px;
  color: #666;
}
.project-delete {
  opacity: 0;
  background: none;
  border: none;
  color: #f66;
  cursor: pointer;
  font-size: 14px;
  padding: 4px;
  transition: opacity 0.2s;
}
.project-item:hover .project-delete {
  opacity: 1;
}
.project-delete:hover {
  color: #f99;
}
.new-project-btn {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  background: #4a6a8a;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.new-project-btn:hover {
  background: #5a7a9a;
}
.clear-all-btn {
  margin-top: 15px;
  width: 100%;
  padding: 8px;
  background: #4a3a3a;
  border: none;
  border-radius: 4px;
  color: #faa;
  font-size: 11px;
  cursor: pointer;
}
.clear-all-btn:hover {
  background: #5a4a4a;
}

/* Main content */
.main-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  min-width: 0;
}
h1 {
  text-align: center;
  margin-bottom: 10px;
}
.container {
  max-width: 1400px;
  margin: 0 auto;
}

/* Upload Section */
.upload-section {
  background: #2a2a4a;
  border-radius: 12px;
  padding: 30px;
  margin-bottom: 30px;
  transition: opacity 0.3s, max-height 0.3s;
}
.upload-section.hidden {
  display: none;
}
.upload-section h2 {
  margin-top: 0;
  margin-bottom: 20px;
}

/* File dropzone - empty state */
.file-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  width: 100%;
  min-height: 200px;
  background: #3a3a5a;
  border: 2px dashed #555;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.file-dropzone:hover,
.file-dropzone.dragover {
  border-color: #5a7a9a;
  background: #454570;
}
.file-dropzone.hidden {
  display: none;
}
.file-dropzone input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dropzone-text {
  font-size: 18px;
  color: #aaa;
}
.dropzone-filename {
  font-size: 14px;
  color: #888;
  max-width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Image selected state */
.image-selected-row {
  display: none;
  align-items: center;
  gap: 16px;
}
.image-selected-row.visible {
  display: flex;
}
.image-preview {
  width: 100px;
  height: 100px;
  border-radius: 8px;
  overflow: hidden;
  background: #1a1a2e;
  border: 2px solid #444;
  flex-shrink: 0;
}
.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.selected-file-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.selected-filename {
  font-size: 14px;
  color: #ccc;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.change-file-btn {
  padding: 6px 12px;
  background: #3a3a5a;
  border: 1px solid #555;
  border-radius: 4px;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  width: fit-content;
}
.change-file-btn:hover {
  background: #4a4a6a;
  color: #fff;
  border-color: #666;
}
.upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-end;
}
.upload-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.upload-group label {
  font-size: 14px;
  color: #aaa;
}
.upload-group input[type="file"] {
  padding: 10px;
  background: #3a3a5a;
  border: 2px dashed #555;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
}
.upload-group input[type="file"]:hover {
  border-color: #777;
}
.upload-group input[type="number"] {
  padding: 10px;
  background: #3a3a5a;
  border: 1px solid #555;
  border-radius: 6px;
  color: #fff;
  width: 100px;
  font-size: 16px;
}
.upload-group input[type="number"].auto-calculated {
  border-color: #5a7a9a;
  font-style: italic;
}


/* Step groups with animations */
.step-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 0;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  transition: opacity 0.3s ease, max-height 0.3s ease, margin-top 0.3s ease;
  pointer-events: none;
}
.step-group.visible {
  opacity: 1;
  max-height: 200px;
  margin-top: 20px;
  pointer-events: auto;
}
.step-group > label {
  font-size: 14px;
  color: #aaa;
  margin-bottom: 4px;
}

/* Size preset buttons */
.size-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.preset-btn {
  padding: 10px 16px;
  background: #3a3a5a;
  border: 2px solid transparent;
  border-radius: 6px;
  color: #aaa;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.preset-btn:hover {
  background: #4a4a6a;
  color: #fff;
}
.preset-btn.active {
  border-color: #5a7a9a;
  background: #4a5a7a;
  color: #fff;
}

/* Disabled preset buttons */
.preset-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #252535;
  color: #666;
  border: 2px dashed #444;
  text-decoration: line-through;
}
.preset-btn:disabled:hover {
  background: #252535;
  color: #666;
}

/* Preset disabled note */
.preset-note {
  display: none;
  font-size: 12px;
  color: #888;
  margin-top: 10px;
  font-style: italic;
}
.preset-note.visible {
  display: block;
}

/* Mesh options */
.mesh-options {
  display: flex;
  gap: 8px;
}
.mesh-btn {
  padding: 10px 20px;
  background: #3a3a5a;
  border: 2px solid transparent;
  border-radius: 6px;
  color: #aaa;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.mesh-btn:hover {
  background: #4a4a6a;
  color: #fff;
}
.mesh-btn.active {
  border-color: #5a7a9a;
  background: #4a5a7a;
  color: #fff;
}

/* Unit toggle */
.unit-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}
.unit-btn {
  padding: 6px 14px;
  background: #3a3a5a;
  border: 1px solid #555;
  border-radius: 4px;
  color: #888;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.unit-btn:hover {
  background: #4a4a6a;
  color: #ccc;
}
.unit-btn.active {
  background: #4a5a7a;
  border-color: #5a7a9a;
  color: #fff;
}

/* Aspect ratio checkbox */
.aspect-ratio-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  cursor: pointer;
  font-size: 13px;
  color: #aaa;
}
.aspect-ratio-checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: #5a7a9a;
  cursor: pointer;
}
.aspect-ratio-checkbox:hover {
  color: #fff;
}

/* Dimensions row */
.dimensions-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.dimension-input {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dimension-input .dimension-label {
  font-size: 12px;
  color: #888;
}
.dimension-input input[type="number"] {
  padding: 10px;
  background: #3a3a5a;
  border: 1px solid #555;
  border-radius: 6px;
  color: #fff;
  width: 100px;
  font-size: 16px;
}
.dimension-input input[type="number"].auto-calculated {
  border-color: #5a7a9a;
  font-style: italic;
}

/* Colors input in step group */
.step-group input[type="number"] {
  padding: 10px;
  background: #3a3a5a;
  border: 1px solid #555;
  border-radius: 6px;
  color: #fff;
  width: 100px;
  font-size: 16px;
}

.convert-btn {
  padding: 12px 30px;
  background: #5a7a9a;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s;
}
.convert-btn:hover {
  background: #6a8aaa;
}
.convert-btn:disabled {
  background: #444;
  cursor: not-allowed;
}
.status {
  margin-top: 15px;
  padding: 10px;
  border-radius: 6px;
  display: none;
}
.status.visible {
  display: block;
}
.status.processing {
  background: #3a4a5a;
  color: #8af;
}
.status.success {
  background: #2a4a3a;
  color: #8fa;
}
.status.error {
  background: #4a2a3a;
  color: #faa;
}

/* Controls */
.controls {
  text-align: center;
  margin-bottom: 20px;
  display: none;
}
.controls.visible {
  display: block;
}
.controls label {
  margin-right: 20px;
}
.controls input[type="range"] {
  width: 150px;
  vertical-align: middle;
}
.controls button {
  padding: 8px 16px;
  margin: 0 5px;
  border: none;
  border-radius: 4px;
  background: #4a4a6a;
  color: #fff;
  cursor: pointer;
}
.controls button:hover {
  background: #5a5a8a;
}

/* Grid */
.result-section {
  display: none;
}
.result-section.visible {
  display: block;
}
/* Result header with pattern info and edit button */
.result-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.pattern-info {
  text-align: center;
  color: #888;
  margin: 0;
}
.edit-settings-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #5a7a9a;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}
.edit-settings-btn:hover {
  background: #6a8aaa;
}
.edit-settings-btn svg {
  flex-shrink: 0;
}
.grid-wrapper {
  overflow: auto;
  margin-bottom: 30px;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 10px;
  text-align: center;
}
.grid {
  display: inline-grid;
  gap: 0;
  border: 2px solid #333;
  border-radius: 8px;
  overflow: hidden;
}
.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
  font-weight: bold;
  border: 1px solid rgba(0,0,0,0.2);
  cursor: pointer;
  transition: transform 0.1s;
}
.cell:hover {
  transform: scale(1.5);
  z-index: 10;
  box-shadow: 0 0 10px rgba(255,255,255,0.5);
}
.cell.show-codes {
  font-size: 6px;
}

/* Legend */
.legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: #2a2a4a;
  border-radius: 6px;
}
.legend-swatch {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  border: 2px solid #555;
  flex-shrink: 0;
}
.legend-info {
  font-size: 13px;
}
.legend-info strong {
  display: block;
  font-size: 16px;
}
.legend-info .hex {
  color: #aaa;
}
.legend-info .count {
  color: #888;
  font-size: 11px;
}
h2 {
  margin-top: 0;
}

/* Download buttons */
.download-section {
  display: none;
  margin-bottom: 25px;
  text-align: center;
}
.download-section.visible {
  display: block;
}
.download-btn {
  padding: 10px 20px;
  margin: 5px;
  background: #4a6a4a;
  border: none;
  border-radius: 6px;
  color: #fff;
  cursor: pointer;
  font-size: 14px;
}
.download-btn:hover {
  background: #5a7a5a;
}

/* Mobile menu toggle button */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 1001;
  background: #4a6a8a;
  border: none;
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  color: #fff;
}
.mobile-menu-toggle svg {
  width: 24px;
  height: 24px;
  display: block;
}
.mobile-menu-toggle .close-icon {
  display: none;
}
.mobile-menu-toggle.active .menu-icon {
  display: none;
}
.mobile-menu-toggle.active .close-icon {
  display: block;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
}
.sidebar-overlay.visible {
  display: block;
}

/* ================================
   MOBILE RESPONSIVE STYLES
   ================================ */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }
  
  /* Mobile menu toggle */
  .mobile-menu-toggle {
    display: block;
  }
  
  /* Sidebar becomes a slide-out drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    padding-top: 70px;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  
  /* Main content takes full width */
  .main-content {
    padding: 70px 15px 20px 15px;
    width: 100%;
  }
  
  /* Smaller heading on mobile */
  h1 {
    font-size: 24px;
    margin-bottom: 5px;
  }
  .main-content > .container > p {
    font-size: 14px;
  }
  
  /* Upload section adjustments */
  .upload-section {
    padding: 20px 15px;
  }
  .upload-section h2 {
    font-size: 18px;
  }
  
  /* File dropzone */
  .file-dropzone {
    min-height: 150px;
    padding: 20px;
  }
  .dropzone-text {
    font-size: 16px;
    text-align: center;
  }
  
  /* Image selected row stacks vertically */
  .image-selected-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .image-preview {
    width: 80px;
    height: 80px;
  }
  .selected-filename {
    max-width: 100%;
  }
  
  /* Size presets wrap better */
  .size-presets {
    gap: 6px;
  }
  .preset-btn {
    padding: 8px 12px;
    font-size: 12px;
    flex: 1 1 auto;
    min-width: calc(50% - 6px);
    text-align: center;
  }
  
  /* Mesh options on mobile */
  .mesh-options {
    gap: 6px;
  }
  .mesh-btn {
    flex: 1;
    padding: 10px 14px;
    font-size: 13px;
  }
  
  /* Unit toggle on mobile */
  .unit-toggle {
    margin-bottom: 10px;
  }
  .unit-btn {
    flex: 1;
    text-align: center;
  }
  
  /* Result header on mobile */
  .result-header {
    flex-direction: column;
    gap: 12px;
  }
  .edit-settings-btn {
    width: 100%;
    max-width: 200px;
    justify-content: center;
  }
  
  /* Dimensions row stacks on mobile */
  .dimensions-row {
    flex-wrap: wrap;
    gap: 10px;
  }
  .dimension-input {
    flex: 1;
    min-width: 80px;
  }
  .dimension-input input[type="number"] {
    width: 100%;
  }
  
  /* Full width inputs */
  .step-group input[type="number"] {
    width: 100%;
    max-width: 150px;
  }
  
  /* Convert button full width */
  .convert-btn {
    width: 100%;
    padding: 15px;
    font-size: 18px;
  }
  
  /* Controls wrap on mobile */
  .controls {
    display: none;
    flex-direction: column;
    gap: 15px;
    align-items: center;
  }
  .controls.visible {
    display: flex;
  }
  .controls label {
    margin-right: 0;
    display: flex;
    align-items: center;
    gap: 10px;
  }
  .controls input[type="range"] {
    width: 120px;
  }
  .controls button {
    padding: 12px 20px;
    font-size: 14px;
    width: 100%;
    max-width: 200px;
  }
  
  /* Grid wrapper scrolls horizontally */
  .grid-wrapper {
    margin-left: -15px;
    margin-right: -15px;
    padding-left: 15px;
    padding-right: 15px;
  }
  
  /* Legend adjusts */
  .legend {
    grid-template-columns: 1fr;
  }
  
  /* Download buttons stack */
  .download-section {
    display: none;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
  }
  .download-section.visible {
    display: flex;
  }
  .download-btn {
    width: 100%;
    margin: 0;
    padding: 14px 20px;
    font-size: 15px;
  }
}

/* Small phone adjustments */
@media (max-width: 380px) {
  .preset-btn {
    min-width: 100%;
  }
  .sidebar {
    width: 100%;
  }
}
