.pce-root {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "topbar topbar"
    "sidebar canvas"
    "frames frames";
  width: 100%;
  height: 100%;
  min-height: 0;
  color: #ddd;
  background: #1a1a1a;
}

.pce-topbar {
  grid-area: topbar;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-bottom: 1px solid #3a3a3a;
}

.pce-topbar input[type="color"] {
  width: 26px;
  height: 26px;
  padding: 0;
  background: none;
  border: 1px solid #555;
  border-radius: 4px;
}

.pce-topbar button {
  min-height: 26px;
  padding: 2px 6px;
  font-size: 13px;
  color: inherit;
  background: #262626;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
}

.pce-topbar button:disabled {
  cursor: default;
  opacity: 0.4;
}

.pce-topbar button.active {
  background: #345;
  border-color: #567;
}

/* Transient feedback for a failed Paste (see flashPasteError in canvas-editor.js) --
   its title attribute (native browser tooltip) carries the actual message. */
.pce-topbar button.pce-flash-error {
  background: #522;
  border-color: #a55;
}

.pce-spacer {
  flex: 1 1 auto;
}

.pce-topbar [data-pce-zoom-label] {
  min-width: 32px;
  font-size: 11px;
  text-align: center;
  color: #999;
}

.pce-size {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #999;
}

.pce-size input[type="range"] {
  width: 60px;
}

.pce-size [data-pce-size-label] {
  min-width: 14px;
  text-align: center;
  color: #ddd;
}

/* Left column: palette on top, tools below -- both live under .pce-sidebar so their rules
   out-specificity editor.css's ".prop-editor-window button/input" floor (min-height:28px etc)
   via the extra ancestor class, instead of silently losing that cascade fight. */
.pce-sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px;
  overflow-y: auto;
  border-right: 1px solid #3a3a3a;
}

/* Ported from face-picker.js's #facePalette .fp-8bit-grid/.fp-8bit-cell (its 256-swatch
   custom color popup) -- same fixed 9px cells, no gap, black grid border, white hover outline. */
.pce-sidebar .pce-palette-grid {
  display: grid;
  grid-template-columns: repeat(16, 9px);
  grid-template-rows: repeat(16, 9px);
  gap: 0;
  border: 1px solid #000;
  align-self: flex-start;
}

.pce-sidebar .pce-swatch {
  width: 9px;
  height: 9px;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  cursor: pointer;
}

.pce-sidebar .pce-swatch:hover {
  outline: 1px solid #fff;
  outline-offset: -1px;
}

/* Persistent selection ring -- outline-color is set inline per swatch (black or white,
   whichever contrasts with that swatch's own color) so it stays legible on every hue. */
.pce-sidebar .pce-swatch.selected {
  outline-width: 2px;
  outline-style: solid;
  outline-offset: -2px;
}

.pce-recent-label {
  margin-top: 2px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #888;
}

/* Same 16-wide grid as the main palette, but fixed at 4 rows (64 cells) regardless of how
   many colors have actually been picked yet -- unfilled cells render via .pce-swatch-empty. */
.pce-sidebar .pce-recent-grid {
  grid-template-rows: repeat(4, 9px);
}

.pce-sidebar .pce-swatch-empty {
  background:
    linear-gradient(45deg, #2c2c2c 25%, transparent 25%, transparent 75%, #2c2c2c 75%) 0 0 / 6px 6px,
    linear-gradient(45deg, #2c2c2c 25%, #242424 25%, #242424 75%, #2c2c2c 75%) 3px 3px / 6px 6px;
  cursor: default;
}

.pce-sidebar .pce-swatch-empty:hover {
  outline: none;
}

.pce-tools {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  width: 144px;
}

.pce-sidebar .pce-tool-btn {
  width: 100%;
  aspect-ratio: 1;
  min-height: 0;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  color: inherit;
  background: #262626;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
}

.pce-sidebar .pce-tool-btn.active {
  background: #345;
  border-color: #567;
}

.pce-canvas-wrap {
  grid-area: canvas;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: auto;
}

.pce-canvas-wrap canvas {
  image-rendering: pixelated;
}

.pce-checker,
.pce-paint,
.pce-grid-overlay {
  grid-area: 1 / 1;
  cursor: crosshair;
}

/* Sits visually on top of the paint canvas but must never intercept pointer events, or
   painting would stop working the moment Pixelize is drawing grid lines over the strokes. */
.pce-grid-overlay {
  pointer-events: none;
}

.pce-frames {
  grid-area: frames;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  overflow-x: auto;
  border-top: 1px solid #3a3a3a;
}

.pce-frame-strip {
  display: flex;
  gap: 4px;
}

.pce-thumb {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  background:
    linear-gradient(45deg, #2c2c2c 25%, transparent 25%, transparent 75%, #2c2c2c 75%) 0 0 / 8px 8px,
    linear-gradient(45deg, #2c2c2c 25%, #242424 25%, #242424 75%, #2c2c2c 75%) 4px 4px / 8px 8px;
  border: 1px solid #555;
  border-radius: 3px;
  cursor: pointer;
}

.pce-thumb.active {
  border-color: #6cf;
  box-shadow: 0 0 0 1px #6cf;
}

.pce-frame-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.pce-frame-actions button:disabled {
  cursor: default;
  opacity: 0.4;
}

.pce-frame-actions button {
  min-height: 26px;
  padding: 2px 8px;
  font-size: 12px;
  color: inherit;
  background: #262626;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
}

.pce-pixelize-backdrop {
  position: fixed;
  inset: 0;
  z-index: 12500;
  display: grid;
  place-items: center;
  background: rgba(10, 10, 12, 0.6);
}

.pce-pixelize-backdrop.hidden {
  display: none;
}

.pce-pixelize-dialog {
  display: grid;
  gap: 10px;
  width: min(260px, 90vw);
  padding: 14px;
  color: #ddd;
  background: #262626;
  border: 1px solid #555;
  border-radius: 6px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}

.pce-pixelize-dialog h3 {
  margin: 0;
  font-size: 13px;
}

.pce-pixelize-field {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: #ccc;
}

.pce-pixelize-field input {
  box-sizing: border-box;
  width: 100%;
  min-height: 28px;
  padding: 2px 6px;
  color: inherit;
  background: #1a1a1a;
  border: 1px solid #555;
  border-radius: 4px;
}

.pce-pixelize-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pce-pixelize-actions button {
  min-height: 28px;
  padding: 3px 10px;
  color: inherit;
  background: #1a1a1a;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
}

.pce-pixelize-actions button.primary {
  background: #345;
  border-color: #567;
}
