.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;
  transition: transform 0.1s ease;
}

@keyframes colorPickAnimation {
  0% {
    transform: scale(1) translateY(0) rotate(0deg);
  }
  25% {
    transform: scale(1.4) translateY(-8px) rotate(-3deg);
  }
  50% {
    transform: scale(0.85) translateY(3px) rotate(2deg);
  }
  70% {
    transform: scale(1.1) translateY(-2px) rotate(-1deg);
  }
  85% {
    transform: scale(0.98) translateY(1px) rotate(0.5deg);
  }
  100% {
    transform: scale(1) translateY(0) rotate(0deg);
  }
}

.pce-topbar input[type="color"].color-picked {
  animation: colorPickAnimation 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.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;
  color: #fff;
}

.pce-checkbox-icon {
  display: inline-block;
  font-size: 14px;
  margin-right: 2px;
  transition: transform 0.2s ease;
}

.pce-topbar button.active .pce-checkbox-icon {
  color: #8f8;
}

.pce-topbar button:not(.active) .pce-checkbox-icon {
  color: #888;
}

/* 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;
}

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

.pce-pentip [data-pce-pentip] {
  min-width: 26px;
  min-height: 26px;
  padding: 0 4px;
  font-size: 14px;
  line-height: 1;
}

/* 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;
}

/* Host wraps the 256-swatch grid so the face-offset XY overlay can sit on top of it
   without covering the recent-history strip or tool buttons below. */
.pce-palette-host {
  position: relative;
  align-self: flex-start;
  width: 146px;  /* 16*9px cells + 1px border each side */
  height: 146px;
}

/* 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;
}

/* Face-offset XY coordinate overlay -- covers the palette while adjusting offset. */
.pce-xy-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  box-sizing: border-box;
  color: rgba(255, 255, 255, 0.75);
  background: rgba(0, 0, 0, 0.88);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.pce-xy-overlay.visible {
  opacity: 1;
  visibility: visible;
}

.pce-xy-overlay.fading {
  opacity: 0;
  visibility: hidden;
}

.pce-xy-svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
}

.pce-xy-hline,
.pce-xy-vline {
  stroke-dashoffset: 0;
  animation: pce-xy-line 10s linear infinite;
}

.pce-xy-pulse {
  stroke-dashoffset: 0;
  animation: pce-xy-rotate 2s ease infinite alternate;
}

.pce-xy-labels {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  box-sizing: border-box;
  padding: 8px 10px;
  font-family: ui-monospace, 'Source Code Pro', Menlo, monospace;
  font-size: 12px;
  line-height: 1.3;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(0, 0, 0, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

.pce-xy-labels.visible {
  opacity: 1;
  visibility: visible;
}

.pce-xy-labels.fading {
  opacity: 0;
  visibility: hidden;
}

@keyframes pce-xy-rotate {
  to {
    stroke-dashoffset: 100;
    fill: rgba(255, 255, 255, 0);
    stroke-dasharray: 20 27;
  }
}

@keyframes pce-xy-line {
  to {
    stroke-dashoffset: 200;
  }
}

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

/* Remapped #fedbfe slot: white swatch with a red X -- selecting it paints transparent. */
.pce-sidebar .pce-swatch.pce-swatch-transparent {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, transparent 42%, #e22 42%, #e22 58%, transparent 58%),
    linear-gradient(-45deg, transparent 42%, #e22 42%, #e22 58%, transparent 58%);
}

.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;
}

/* Recent Color History block -- label + 4-row grid share a relative host so the
   face-offset X/Y readout can cover that slot instead of the main palette. */
.pce-recent-host {
  position: relative;
  align-self: flex-start;
  width: 146px;
}

.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;
  display: grid;
  place-items: center;
}

.pce-tool-btn img {
  width: 60%;
  height: 60%;
  object-fit: contain;
  display: block;
  pointer-events: none;
}

.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;
  perspective: 1000px;
}

.pce-canvas-wrap canvas {
  image-rendering: pixelated;
  transform-style: preserve-3d;
}

.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;
  border-top: 1px solid #3a3a3a;
  position: relative;
}

.pce-frame-strip {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  flex: 1;
  padding-right: 8px;
}

.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: #fff;
  box-shadow: 0 0 0 1px #fff;
}

.pce-frame-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.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;
}

