/* ===== Online Pixel Editor ===== */
.editor-app {
  padding: 70px 0 0;
  min-height: 100vh;
  background: #1a1a28;
  display: flex;
  flex-direction: column;
}
.editor-toolbar {
  background: #252538;
  border-bottom: 1px solid #3a3a52;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  position: sticky;
  top: 60px;
  z-index: 50;
}
.tb-group {
  display: flex;
  gap: 2px;
  background: #1e1e2e;
  border-radius: 6px;
  padding: 3px;
}
.tb-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: #9898b0;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  padding: 0;
}
.tb-btn:hover { background: #3a3a52; color: #e4e4f0; }
.tb-btn.active { background: #ff9f43; color: #1e1e2e; }
.tb-btn svg { width: 18px; height: 18px; }
.tb-sep { width: 1px; height: 28px; background: #3a3a52; margin: 0 4px; }
.tb-label { font-size: 12px; color: #9898b0; margin-right: 4px; }
.tb-select {
  background: #1e1e2e;
  color: #e4e4f0;
  border: 1px solid #3a3a52;
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.tb-select:focus { outline: none; border-color: #ff9f43; }
.tb-color-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.tb-color-current {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  border: 2px solid #3a3a52;
  cursor: pointer;
  padding: 0;
  position: relative;
  overflow: hidden;
}
.tb-color-current input { opacity: 0; width: 100%; height: 100%; cursor: pointer; border: none; }
.tb-color-current::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--cur-color, #ff9f43);
  z-index: -1;
}
.tb-action {
  background: #1e1e2e;
  color: #9898b0;
  border: 1px solid #3a3a52;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 4px;
}
.tb-action:hover { background: #3a3a52; color: #e4e4f0; }
.tb-action.primary { background: #ff9f43; color: #1e1e2e; border-color: #ff9f43; font-weight: 600; }
.tb-action.primary:hover { background: #e88a2e; }
.tb-action:disabled { opacity: .4; cursor: not-allowed; }

/* Main layout */
.editor-main {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.editor-left {
  width: 52px;
  background: #252538;
  border-right: 1px solid #3a3a52;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
}
.tool-btn {
  width: 38px;
  height: 38px;
  border: none;
  background: transparent;
  color: #9898b0;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  position: relative;
}
.tool-btn:hover { background: #3a3a52; color: #e4e4f0; }
.tool-btn.active { background: #ff9f43; color: #1e1e2e; }
.tool-btn svg { width: 20px; height: 20px; }
.tool-btn[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  left: 46px;
  top: 50%;
  transform: translateY(-50%);
  background: #1e1e2e;
  color: #e4e4f0;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  border: 1px solid #3a3a52;
  z-index: 100;
  pointer-events: none;
}

/* Canvas area */
.editor-canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px;
  background:
    linear-gradient(45deg, #22223a 25%, transparent 25%),
    linear-gradient(-45deg, #22223a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #22223a 75%),
    linear-gradient(-45deg, transparent 75%, #22223a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #1e1e2e;
}
.canvas-wrapper {
  position: relative;
  image-rendering: pixelated;
  box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
#editorCanvas {
  display: block;
  image-rendering: pixelated;
  cursor: crosshair;
  background: transparent;
}
#gridCanvas {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}

/* Right panel */
.editor-right {
  width: 220px;
  background: #252538;
  border-left: 1px solid #3a3a52;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.panel-section {
  padding: 12px;
  border-bottom: 1px solid #3a3a52;
}
.panel-section h4 {
  font-size: 11px;
  color: #9898b0;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0 0 10px;
  font-family: 'Press Start 2P', monospace;
}
.palette-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
}
.palette-swatch {
  aspect-ratio: 1;
  border-radius: 3px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .1s;
  position: relative;
}
.palette-swatch:hover { transform: scale(1.15); }
.palette-swatch.active { border-color: #fff; box-shadow: 0 0 0 1px #ff9f43; }
.palette-swatch.transparent {
  background:
    linear-gradient(45deg, #ccc 25%, transparent 25%),
    linear-gradient(-45deg, #ccc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ccc 75%),
    linear-gradient(-45deg, transparent 75%, #ccc 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #fff;
}
.preview-box {
  width: 100%;
  aspect-ratio: 1;
  background:
    linear-gradient(45deg, #333 25%, transparent 25%),
    linear-gradient(-45deg, #333 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #333 75%),
    linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-color: #1a1a28;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#previewCanvas {
  image-rendering: pixelated;
  max-width: 100%;
  max-height: 100%;
}
.size-btns { display: flex; gap: 4px; flex-wrap: wrap; }
.size-btn {
  flex: 1;
  min-width: 50px;
  background: #1e1e2e;
  color: #9898b0;
  border: 1px solid #3a3a52;
  border-radius: 4px;
  padding: 6px 4px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.size-btn:hover { border-color: #ff9f43; color: #e4e4f0; }
.size-btn.active { background: #ff9f43; color: #1e1e2e; border-color: #ff9f43; font-weight: 600; }

/* Timeline */
.editor-timeline {
  background: #252538;
  border-top: 1px solid #3a3a52;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.timeline-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}
.ctrl-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: #1e1e2e;
  color: #9898b0;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.ctrl-btn:hover { background: #3a3a52; color: #e4e4f0; }
.ctrl-btn.play-btn { background: #ff9f43; color: #1e1e2e; }
.ctrl-btn.play-btn:hover { background: #e88a2e; }
.ctrl-btn svg { width: 16px; height: 16px; }
.fps-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #9898b0;
}
.fps-control input {
  width: 50px;
  background: #1e1e2e;
  color: #e4e4f0;
  border: 1px solid #3a3a52;
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 12px;
  text-align: center;
}
.frames-list {
  flex: 1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0;
  align-items: center;
}
.frame-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border: 2px solid #3a3a52;
  border-radius: 4px;
  cursor: pointer;
  background:
    linear-gradient(45deg, #333 25%, transparent 25%),
    linear-gradient(-45deg, #333 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #333 75%),
    linear-gradient(-45deg, transparent 75%, #333 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
  background-color: #1a1a28;
  flex-shrink: 0;
  overflow: hidden;
  transition: border-color .15s;
}
.frame-thumb:hover { border-color: #9898b0; }
.frame-thumb.active { border-color: #ff9f43; }
.frame-thumb canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}
.frame-thumb .frame-num {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,.7);
  color: #fff;
  font-size: 9px;
  text-align: center;
  line-height: 14px;
}
.frame-thumb .frame-del {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ff6b6b;
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 11px;
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
}
.frame-thumb:hover .frame-del { display: flex; }
.add-frame-btn {
  width: 56px;
  height: 56px;
  border: 2px dashed #3a3a52;
  border-radius: 4px;
  background: transparent;
  color: #9898b0;
  cursor: pointer;
  font-size: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.add-frame-btn:hover { border-color: #ff9f43; color: #ff9f43; }

/* Onion skin opacity */
.opacity-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #9898b0;
}
.opacity-row input[type=range] { flex: 1; accent-color: #ff9f43; }

/* Modal */
.editor-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.editor-modal.show { display: flex; }
.editor-modal-box {
  background: #252538;
  border: 1px solid #3a3a52;
  border-radius: 8px;
  padding: 24px;
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  text-align: center;
}
.modal-box h3 { margin: 0 0 16px; color: #ff9f43; }
.modal-box img {
  image-rendering: pixelated;
  max-width: 400px;
  max-height: 400px;
  border: 1px solid #3a3a52;
  border-radius: 4px;
  background: #1a1a28;
}
.modal-actions { margin-top: 16px; display: flex; gap: 8px; justify-content: center; }

/* Responsive */
@media (max-width: 900px) {
  .editor-right { width: 160px; }
  .editor-toolbar { gap: 6px; padding: 6px 8px; }
  .tb-action span { display: none; }
}
@media (max-width: 600px) {
  .editor-right { display: none; }
  .editor-timeline { flex-wrap: wrap; gap: 8px; padding: 8px; }
  .frames-list { order: 3; width: 100%; }
}
