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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 30px;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Workspace */
.workspace {
    display: flex;
    gap: 30px;
    padding: 30px;
    flex-wrap: wrap;
}

/* Canvas Section */
.canvas-section {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.canvas-wrapper {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}

#characterCanvas {
    max-width: 100%;
    height: auto;
    display: block;
    border: 2px solid #ddd;
    border-radius: 8px;
    background: white;
}

.canvas-controls {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
}

/* Layers Section */
.layers-section {
    flex: 0 0 400px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.layers-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}

.layers-header h2 {
    color: #667eea;
    font-size: 1.5rem;
}

.layers-list {
    background: #f8f9fa;
    border-radius: 15px;
    padding: 20px;
    min-height: 400px;
    max-height: 600px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    text-align: center;
}

.empty-state p {
    margin: 5px 0;
}

.empty-state .hint {
    font-size: 0.9rem;
}

/* Layer Item */
.layer-item {
    background: white;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: all 0.3s ease;
}

.layer-main {
    display: flex;
    align-items: center;
    gap: 15px;
}

.layer-item:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.layer-item.dragging {
    opacity: 0.5;
}

/* Transform sliders */
.layer-transform {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 8px;
    border-top: 1px solid #eee;
}

.xform-row {
    display: grid;
    grid-template-columns: 40px 1fr 48px;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: #555;
}

.xform-label {
    font-weight: 600;
    color: #667eea;
}

.xform-row input[type="range"] {
    width: 100%;
    accent-color: #667eea;
    cursor: pointer;
}

.xform-value {
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: #333;
}

.xform-reset {
    align-self: flex-end;
    margin-top: 2px;
    padding: 4px 10px;
    background: #f0f0f0;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #555;
    cursor: pointer;
    transition: background 0.2s ease;
}

.xform-reset:hover {
    background: #667eea;
    color: white;
}

/* Layer Thumbnail */
.layer-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #ddd;
    flex-shrink: 0;
    background: #f0f0f0;
}

.layer-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Layer Info */
.layer-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.layer-name {
    font-weight: 600;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-size {
    font-size: 0.85rem;
    color: #999;
}

.skin-tone-toggle {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85rem;
    color: #667eea;
    cursor: pointer;
    user-select: none;
}

.skin-tone-toggle input[type="checkbox"] {
    cursor: pointer;
}

.skin-tone-toggle span {
    font-weight: 500;
}

/* Layer Controls */
.layer-controls {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    flex-shrink: 0;
    max-width: 90px;
}

.layer-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    background: #f0f0f0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
}

.layer-btn:hover {
    background: #667eea;
    color: white;
}

.layer-btn.active {
    background: #667eea;
    color: white;
}

.layer-btn.danger:hover {
    background: #dc3545;
    color: white;
}

/* Buttons */
.btn-primary, .btn-secondary, .btn-add {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex: 1;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    flex: 1;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-add {
    background: #28a745;
    color: white;
}

.btn-add:hover {
    background: #218838;
    transform: translateY(-2px);
}

/* Responsive */
@media (max-width: 768px) {
    .workspace {
        flex-direction: column;
    }

    .layers-section {
        flex: 1;
    }

    header h1 {
        font-size: 2rem;
    }

    .layers-header {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Scrollbar */
.layers-list::-webkit-scrollbar {
    width: 8px;
}

.layers-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.layers-list::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
}

.layers-list::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Skin Tone Section */
.skin-tone-section {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.skin-tone-section h3 {
    color: #667eea;
    margin-bottom: 15px;
    font-size: 1.2rem;
}

.skin-tone-swatches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 10px;
}

.skin-tone-swatch {
    aspect-ratio: 1;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 3px solid transparent;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.skin-tone-swatch:hover {
    transform: scale(1.1);
}

.skin-tone-swatch.active {
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.3);
}

/* Gallery Modal */

.gallery-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
}

.gallery-modal.hidden {
  display: none;
}

.gallery-panel {
  background: #1a1a1a;
  color: #fff;
  width: min(900px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.gallery-header {
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #333;
  flex: 0 0 auto;
}

.gallery-header h2,
.gallery-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
}

.gallery-header button {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  line-height: 1;
}

.gallery-header button:hover {
  background: #333;
}

.gallery-grid {
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  overflow-y: auto;
  flex: 1 1 auto;
  align-content: start;
}

.gallery-footer {
  padding: 12px 20px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  border-top: 1px solid #333;
  flex: 0 0 auto;
}

.gallery-footer button {
  padding: 10px 20px;
  background: #28a745;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

.gallery-footer button:disabled {
  background: #4a4a4a;
  cursor: not-allowed;
}

.gallery-footer button:not(:disabled):hover {
  background: #218838;
}

.gallery-item {
  aspect-ratio: 1;
  border: 2px solid transparent;
  cursor: pointer;
  background: #2a2a2a;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: transform 0.15s ease, background 0.15s ease;
  overflow: hidden;
  user-select: none;
}

.gallery-item:hover {
  background: #333;
  transform: scale(1.03);
}

.gallery-item.selected {
  border-color: #4caf50;
  background: #2d4a2d;
}

.gallery-item img {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.gallery-label {
  font-size: 0.7rem;
  color: #ccc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  text-align: center;
}

@media (max-width: 700px) {
  .gallery-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 12px;
  }
}

@media (max-width: 420px) {
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

.gallery-grid::-webkit-scrollbar {
  width: 8px;
}
.gallery-grid::-webkit-scrollbar-track {
  background: #1a1a1a;
}
.gallery-grid::-webkit-scrollbar-thumb {
  background: #4a4a4a;
  border-radius: 4px;
}
.gallery-grid::-webkit-scrollbar-thumb:hover {
  background: #667eea;
}

