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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: #16213e;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 20px;
  border-bottom: 2px solid #0f3460;
  flex-shrink: 0;
}

header h1 { font-size: 18px; white-space: nowrap; color: #e94560; }

.header-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.canvas-size-group, .action-buttons { display: flex; align-items: center; gap: 6px; }
.canvas-size-group input { width: 60px; }

main { display: flex; flex: 1; overflow: hidden; }

/* Toolbar */
.toolbar {
  width: 200px;
  background: #16213e;
  border-right: 2px solid #0f3460;
  padding: 10px;
  overflow-y: auto;
  flex-shrink: 0;
}

.toolbar h3 {
  font-size: 11px;
  text-transform: uppercase;
  color: #e94560;
  margin: 10px 0 5px;
  letter-spacing: 1px;
}

.toolbar h3:first-child { margin-top: 0; }

.tool-group { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }

.tool-btn {
  padding: 5px 3px;
  font-size: 11px;
  cursor: pointer;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  transition: all 0.15s;
}

.tool-btn:hover { background: #0f3460; }
.tool-btn.active { background: #e94560; color: white; border-color: #e94560; }

button {
  padding: 5px 8px;
  font-size: 11px;
  cursor: pointer;
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid #1a1a5e;
  border-radius: 4px;
  transition: background 0.15s;
}

button:hover { background: #e94560; }

input[type="number"], input[type="text"], select {
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #0f3460;
  border-radius: 4px;
  padding: 3px 5px;
  font-size: 11px;
}

.grid-toggle label, .mirror-mode-label {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

/* Mirror */
.mirror-group { display: flex; flex-direction: column; gap: 4px; }
.mirror-group button { width: 100%; text-align: left; }
.mirror-group select { width: 100%; margin-top: 2px; }
.mirror-mode-label { margin-top: 2px; }

/* Templates */
.template-actions { display: flex; flex-direction: column; gap: 4px; }
.template-actions button { width: 100%; text-align: left; }
.template-list { display: flex; flex-direction: column; gap: 2px; max-height: 150px; overflow-y: auto; }
.template-item {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #1a1a2e;
  border: 1px solid #0f3460;
  border-radius: 3px;
  padding: 3px 5px;
  font-size: 11px;
}
.template-item canvas {
  width: 24px; height: 24px;
  image-rendering: pixelated;
  border: 1px solid #0f3460;
  flex-shrink: 0;
}
.template-item .tpl-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.template-item .tpl-use {
  background: #0f3460; border: none; padding: 2px 6px; border-radius: 3px;
  color: #e0e0e0; cursor: pointer; font-size: 10px; flex-shrink: 0;
}
.template-item .tpl-use:hover { background: #e94560; }
.template-item .tpl-del {
  background: none; border: none; padding: 2px 4px;
  color: #666; cursor: pointer; font-size: 12px; flex-shrink: 0;
}
.template-item .tpl-del:hover { color: #e94560; }

/* File actions */
.file-actions { display: flex; flex-direction: column; gap: 3px; }
.file-actions button { width: 100%; text-align: left; }

/* Canvas section: color bar + canvas */
.canvas-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Color bar */
.color-bar {
  background: #16213e;
  border-bottom: 2px solid #0f3460;
  padding: 6px 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  flex-shrink: 0;
  overflow-x: auto;
}

.color-preview {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 4px;
  border: 2px solid #0f3460;
  background: #000000;
  align-self: center;
}

.color-picker-area { display: flex; flex-direction: column; gap: 4px; }

.picker-mode-tabs { display: flex; gap: 2px; }

.picker-mode-tab {
  padding: 3px 8px;
  font-size: 10px;
  background: #1a1a2e;
  border: 1px solid #0f3460;
}

.picker-mode-tab.active { background: #e94560; border-color: #e94560; }

.picker-panel { display: flex; gap: 6px; align-items: flex-start; }
.picker-panel.hidden { display: none; }

/* Square picker (Photoshop style) */
.square-picker-wrap { display: flex; gap: 4px; }
#svSquare { cursor: crosshair; border-radius: 2px; }
#hueStrip { cursor: crosshair; border-radius: 2px; }

/* Round wheel */
#colorWheel, #brightnessSlider { cursor: crosshair; display: block; border-radius: 4px; }
#brightnessSlider { margin-top: 3px; }

/* HEX */
.hex-row { display: flex; align-items: center; gap: 5px; padding: 4px 0; }
#hexInput { width: 80px; }

/* RGB */
.rgb-row { display: flex; align-items: center; gap: 5px; font-size: 11px; }
.rgb-row label { width: 14px; }
.rgb-row input[type="range"] { width: 120px; }
.rgb-row span { width: 24px; text-align: right; font-size: 10px; }

/* Favorites */
.favorites-section { display: flex; flex-direction: column; gap: 3px; align-self: center; }
.favorites-header { display: flex; align-items: center; gap: 4px; }
.fav-label { font-size: 10px; text-transform: uppercase; color: #e94560; letter-spacing: 1px; }
#btnAddFavorite { padding: 1px 6px; font-size: 12px; line-height: 1; }
.favorites-grid { display: flex; flex-wrap: wrap; gap: 2px; max-width: 180px; }
.fav-color {
  width: 20px; height: 20px;
  border: 1px solid #0f3460;
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  transition: transform 0.1s;
}
.fav-color:hover { transform: scale(1.2); z-index: 1; }
.fav-color .fav-remove {
  display: none;
  position: absolute;
  top: -6px; right: -6px;
  width: 14px; height: 14px;
  background: #e94560;
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 9px;
  line-height: 14px;
  text-align: center;
  padding: 0;
  cursor: pointer;
}
.fav-color:hover .fav-remove { display: block; }

/* Palette */
.palette-section { display: flex; flex-direction: column; gap: 3px; align-self: center; }
.palette-label { font-size: 10px; text-transform: uppercase; color: #e94560; letter-spacing: 1px; }
.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.palette-color {
  width: 18px; height: 18px;
  border: 1px solid #0f3460;
  border-radius: 2px;
  cursor: pointer;
  transition: transform 0.1s;
}
.palette-color:hover { transform: scale(1.2); z-index: 1; }

/* Canvas area */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background:
    linear-gradient(45deg, #12121f 25%, transparent 25%),
    linear-gradient(-45deg, #12121f 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #12121f 75%),
    linear-gradient(-45deg, transparent 75%, #12121f 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #16162a;
}

.canvas-wrapper {
  position: absolute;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.canvas-wrapper canvas {
  position: absolute;
  top: 0; left: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#previewCanvas { pointer-events: none; opacity: 0.5; }
#gridCanvas { pointer-events: none; }
#pixelCanvas { cursor: crosshair; }

.zoom-controls {
  position: absolute;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(22, 33, 62, 0.9);
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid #0f3460;
  z-index: 10;
}

#zoomLevel { font-size: 12px; min-width: 40px; text-align: center; }

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden { display: none; }

.modal-content {
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 8px;
  padding: 20px;
  min-width: 280px;
}

.modal-content h2 { margin-bottom: 12px; color: #e94560; font-size: 16px; }

.export-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.export-options label { font-size: 12px; }
.export-options select { width: 100%; }
.export-preview-info { font-size: 11px; color: #999; }

.template-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.template-form input { width: 100%; }

.modal-actions { display: flex; gap: 6px; justify-content: flex-end; }
#btnDoExport, #btnDoSaveTemplate { background: #e94560; }

/* Scrollbars */
.toolbar::-webkit-scrollbar, .template-list::-webkit-scrollbar { width: 5px; }
.toolbar::-webkit-scrollbar-track, .template-list::-webkit-scrollbar-track { background: #1a1a2e; }
.toolbar::-webkit-scrollbar-thumb, .template-list::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 3px; }
