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

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

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #16213e;
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
  min-height: 42px;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tool-group.separator {
  border-left: 1px solid #0f3460;
  padding-left: 8px;
  margin-left: 2px;
}

.tool-label {
  font-size: 11px;
  color: #8899aa;
  white-space: nowrap;
}

.tool-btn {
  width: 32px;
  height: 32px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
  transition: all 0.15s;
}

.tool-btn svg {
  width: 18px;
  height: 18px;
  fill: #8899aa;
}

.tool-btn:hover {
  background: #1a3a5c;
  border-color: #0f3460;
}

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

.tool-btn.active svg {
  fill: #e94560;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: #667788;
}

.icon-btn:hover {
  background: #1a3a5c;
}

.icon-btn.active {
  background: #0f3460;
}

.icon-btn.active svg {
  fill: #53c28b;
}

#brush-size {
  width: 80px;
  accent-color: #e94560;
}

#brush-size-val {
  font-size: 11px;
  color: #8899aa;
  width: 16px;
  text-align: center;
}

select, input[type="number"] {
  background: #0f3460;
  color: #e0e0e0;
  border: 1px solid #16213e;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  outline: none;
}

select:focus, input[type="number"]:focus {
  border-color: #e94560;
}

#zoom-display {
  font-size: 12px;
  color: #53c28b;
  font-weight: bold;
  min-width: 30px;
}

/* Main Layout */
#main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Left Sidebar - Palette */
#sidebar-left {
  width: 52px;
  background: #16213e;
  border-right: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  gap: 8px;
  flex-shrink: 0;
  overflow-y: auto;
}

#color-preview {
  position: relative;
  width: 40px;
  height: 40px;
  margin-bottom: 4px;
}

#color-fg {
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 28px;
  background: #000000;
  border: 2px solid #e0e0e0;
  border-radius: 3px;
  cursor: pointer;
  z-index: 2;
}

#color-bg {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 28px;
  height: 28px;
  background: #ffffff;
  border: 2px solid #999;
  border-radius: 3px;
  cursor: pointer;
  z-index: 1;
}

#palette {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  width: 100%;
}

.palette-color {
  width: 20px;
  height: 20px;
  border: 1px solid #333;
  border-radius: 2px;
  cursor: pointer;
  margin: 0 auto;
  transition: transform 0.1s;
}

.palette-color:hover {
  transform: scale(1.2);
  border-color: #fff;
  z-index: 1;
}

.palette-color.selected {
  border: 2px solid #e94560;
}

#custom-color {
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100%;
}

#color-picker {
  width: 26px;
  height: 26px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

#color-picker::-webkit-color-swatch-wrapper {
  padding: 1px;
}

#color-picker::-webkit-color-swatch {
  border: 1px solid #555;
  border-radius: 2px;
}

#add-color-btn {
  width: 20px;
  height: 20px;
  background: #0f3460;
  color: #53c28b;
  border: 1px solid #0f3460;
  border-radius: 2px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#add-color-btn:hover {
  background: #1a3a5c;
}

/* Canvas Area */
#canvas-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background: #12121f;
  background-image:
    radial-gradient(circle at 50% 50%, #1a1a2e 0%, #12121f 100%);
}

#canvas-container {
  position: relative;
  image-rendering: pixelated;
  cursor: crosshair;
}

#canvas-main, #canvas-grid, #canvas-overlay {
  position: absolute;
  top: 0;
  left: 0;
  image-rendering: pixelated;
}

#canvas-main {
  z-index: 1;
  background: repeating-conic-gradient(#3a3a4a 0% 25%, #2a2a3a 0% 50%) 50% / 16px 16px;
}

#canvas-grid {
  z-index: 2;
  pointer-events: none;
}

#canvas-overlay {
  z-index: 3;
}

#coordinates {
  position: absolute;
  bottom: 4px;
  left: 8px;
  font-size: 11px;
  color: #667788;
  font-family: 'Consolas', monospace;
}

/* Right Sidebar - Preview */
#sidebar-right {
  width: 140px;
  background: #16213e;
  border-left: 1px solid #0f3460;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  gap: 6px;
  flex-shrink: 0;
}

#sidebar-right h3 {
  font-size: 11px;
  color: #8899aa;
  text-transform: uppercase;
  letter-spacing: 1px;
}

#preview-container {
  background: repeating-conic-gradient(#3a3a4a 0% 25%, #2a2a3a 0% 50%) 50% / 8px 8px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#canvas-preview {
  image-rendering: pixelated;
}

#preview-controls {
  display: flex;
  gap: 4px;
}

#preview-controls select {
  font-size: 11px;
  padding: 2px 4px;
}

/* Timeline */
#timeline {
  display: flex;
  align-items: center;
  background: #16213e;
  border-top: 1px solid #0f3460;
  padding: 6px 10px;
  gap: 8px;
  flex-shrink: 0;
  min-height: 80px;
}

#playback-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

#playback-controls button {
  width: 30px;
  height: 30px;
  border: 1px solid #0f3460;
  border-radius: 4px;
  background: #1a1a2e;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px;
}

#playback-controls button svg {
  width: 16px;
  height: 16px;
  fill: #8899aa;
}

#playback-controls button:hover {
  background: #0f3460;
}

#playback-controls button:hover svg {
  fill: #e94560;
}

#fps-input {
  width: 44px;
  text-align: center;
}

/* Frames */
#frames-container {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
}

#frames-list {
  display: flex;
  gap: 4px;
  padding: 4px;
  min-height: 60px;
}

.frame-thumb {
  width: 56px;
  height: 56px;
  border: 2px solid #0f3460;
  border-radius: 4px;
  cursor: pointer;
  background: repeating-conic-gradient(#3a3a4a 0% 25%, #2a2a3a 0% 50%) 50% / 8px 8px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s;
}

.frame-thumb canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.frame-thumb:hover {
  border-color: #53c28b;
}

.frame-thumb.active {
  border-color: #e94560;
  box-shadow: 0 0 6px rgba(233, 69, 96, 0.4);
}

.frame-thumb .frame-number {
  position: absolute;
  bottom: 1px;
  right: 2px;
  font-size: 9px;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}

#frame-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

#frame-actions button {
  width: 26px;
  height: 26px;
  border: 1px solid #0f3460;
  border-radius: 3px;
  background: #1a1a2e;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px;
}

#frame-actions button svg {
  width: 14px;
  height: 14px;
  fill: #8899aa;
}

#frame-actions button:hover {
  background: #0f3460;
}

#frame-actions button:hover svg {
  fill: #53c28b;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
  background: #0f3460;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #1a3a5c;
}
