/* Pixel Art Editor. #pxe-scoped.
 *
 * tool-theme.css loads AFTER this file and wins every tie, and two of its rules shape this
 * widget whether it likes it or not:
 *
 *  - `#tool-root button:not(.btn):not([class*="tab"])` is (1,2,1) and gives every button
 *    `padding: 8px 13px` — a 28px floor. That is the rule CLAUDE.md records breaking
 *    texture-maker's palette by 19px. The palette swatches and the material rows here are
 *    buttons with no room for that, so their overrides are written with TWO ids,
 *    `#tool-root #pxe button.x` at (2,1,1), which beats (1,2,1) outright instead of tying and
 *    losing on load order. The toggle buttons carry `pxe-tab` on purpose: the tab rule is
 *    excluded from the generic one, and its active state is the site's own green.
 *  - `#tool-root canvas { max-width: 100%; height: auto }` scales every canvas down to its
 *    column, which would make zoom do nothing past the column width. The stage scrolls
 *    instead, so the canvas is released from that rule, again with two ids.
 */

#pxe { display: block; }
#pxe [hidden] { display: none !important; }

#pxe .pxe-layout {
  display: grid;
  grid-template-columns: minmax(200px, 240px) minmax(0, 1fr) minmax(250px, 310px);
  grid-template-areas: "blocks main side";
  gap: 18px;
  align-items: start;
}
#pxe .pxe-blocks { grid-area: blocks; }
#pxe .pxe-main { grid-area: main; }
#pxe .pxe-side { grid-area: side; }
@media (max-width: 1180px) {
  #pxe .pxe-layout {
    grid-template-columns: minmax(190px, 230px) minmax(0, 1fr);
    grid-template-areas: "blocks main" "side side";
  }
  #pxe .pxe-side { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
}
@media (max-width: 760px) {
  #pxe .pxe-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "blocks" "side"; }
  #pxe .pxe-side { grid-template-columns: minmax(0, 1fr); }
}

#pxe .pxe-col { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#pxe .pxe-side { gap: 14px; }
#pxe .pxe-label {
  display: block; font-size: 11px; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; opacity: .75;
}
#pxe .pxe-hint { margin: 0; font-size: 12px; line-height: 1.5; }
#pxe .pxe-note { margin: 0; min-height: 1.3em; font-size: 13px; line-height: 1.5; }

/* ---- palette ---------------------------------------------------------------------------- */

#pxe .pxe-current {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
}
#pxe .pxe-current-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
#pxe .pxe-current-label { font-weight: 700; font-size: 13.5px; line-height: 1.25; }
#pxe .pxe-current-code { font-size: 11px; align-self: flex-start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#pxe .pxe-sprite {
  display: inline-block; flex: 0 0 auto;
  width: 20px; height: 20px;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  border-radius: 2px;
  /* Mid-grey, so black concrete on the dark theme and white wool on the light one keep an edge. */
  box-shadow: 0 0 0 1px rgba(127, 127, 127, .6);
}
#pxe .pxe-sprite-lg { width: 36px; height: 36px; }

#pxe .pxe-search { width: 100%; box-sizing: border-box; padding: 7px 10px; font-size: 13px; }
#pxe .pxe-groups { display: flex; flex-wrap: wrap; gap: 4px; }
#pxe .pxe-groups .pxe-tab { padding: 4px 8px; font-size: 12px; font-weight: 700; cursor: pointer; }

#pxe .pxe-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  gap: 4px;
  max-height: 440px;
  overflow-y: auto;
  padding: 2px;
}
@media (max-width: 760px) { #pxe .pxe-swatches { max-height: 260px; } }
#tool-root #pxe button.pxe-sw {
  padding: 0; min-width: 0; aspect-ratio: 1 / 1;
  display: flex; align-items: stretch; justify-content: stretch;
  background: transparent; border: 2px solid transparent; border-radius: 4px; cursor: pointer;
}
#tool-root #pxe button.pxe-sw .pxe-sprite { width: 100%; height: 100%; }
#tool-root #pxe button.pxe-sw:hover { border-color: var(--line-strong); background: transparent; }
#tool-root #pxe button.pxe-sw.pxe-active { border-color: var(--grass-bright); box-shadow: 0 0 0 1px var(--grass-bright); }

/* ---- toolbar and stage ------------------------------------------------------------------ */

#pxe .pxe-toolbar, #pxe .pxe-viewbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
#pxe .pxe-toolgroup { display: inline-flex; flex-wrap: wrap; gap: 4px; align-items: center; }
#pxe .pxe-tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
#pxe .pxe-tab kbd { font-size: 10px; padding: 0 4px; opacity: .7; line-height: 1.5; }
#pxe .pxe-btn { font-size: 13px; }
#tool-root #pxe button.pxe-btn { padding: 6px 11px; font-size: 13px; }
#tool-root #pxe button.pxe-sq { width: 32px; padding: 6px 0; text-align: center; }
#pxe .pxe-zoom { min-width: 46px; text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; opacity: .8; }

#pxe .pxe-stage {
  position: relative;
  overflow: auto;
  max-height: min(78vh, 820px);
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(127, 127, 127, .1);
  text-align: center;
  line-height: 0;
}
#pxe .pxe-stage.pxe-over { outline: 2px dashed var(--grass-bright); outline-offset: -4px; }
#tool-root #pxe .pxe-stage canvas {
  max-width: none;
  display: inline-block;
  image-rendering: pixelated;
  /* A drag on a phone draws instead of scrolling the page. */
  touch-action: none;
  cursor: crosshair;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
}

#pxe .pxe-under {
  display: flex; gap: 14px; flex-wrap: wrap; min-height: 1.4em;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; opacity: .8;
}
#pxe .pxe-check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

/* ---- side panels ------------------------------------------------------------------------ */

#pxe .pxe-panel { padding: 12px 13px; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 9px; min-width: 0; }
#pxe .pxe-h { margin: 0; font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }

#pxe .pxe-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
#pxe .pxe-stat { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
#pxe .pxe-stat strong { font-size: 17px; line-height: 1.2; font-variant-numeric: tabular-nums; }
#pxe .pxe-statlabel { font-size: 11px; opacity: .72; line-height: 1.25; }

#pxe .pxe-mats { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; max-height: 330px; overflow-y: auto; }
#pxe .pxe-mat { margin: 0; }
#tool-root #pxe button.pxe-matbtn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 4px 6px; border: 1px solid transparent; border-radius: var(--radius);
  background: transparent; font-size: 12.5px; font-weight: 500; text-align: start; cursor: pointer; color: inherit;
}
#tool-root #pxe button.pxe-matbtn:hover { border-color: var(--line-strong); background: transparent; }
#tool-root #pxe .pxe-mat.pxe-active button.pxe-matbtn { border-color: var(--grass-bright); }
#pxe .pxe-matsym { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; min-width: 2ch; text-align: center; }
#pxe .pxe-matname { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
/* --gold is only defined once, for the dark theme; on the light page it measured 1.86:1 against
 * white, and #pxe-mats is data-tnorm-skip, so nothing repaints it. A darker amber there. */
#pxe .pxe-matwarn { font-size: 11px; color: var(--gold); }
:root[data-theme="light"] #pxe .pxe-matwarn { color: #7a5200; }
#pxe .pxe-matcount { flex: 0 0 auto; text-align: end; font-variant-numeric: tabular-nums; font-weight: 700; display: flex; flex-direction: column; }
#pxe .pxe-matstacks { font-size: 10.5px; font-weight: 500; opacity: .7; }

#pxe .pxe-sizerow { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
#pxe .pxe-num { display: flex; flex-direction: column; gap: 4px; font-size: 12px; flex: 1 1 90px; min-width: 0; }
#pxe .pxe-num input, #pxe .pxe-num select { width: 100%; box-sizing: border-box; padding: 6px 8px; font-size: 13px; }
#pxe .pxe-anchor-wrap { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
#pxe .pxe-anchor { display: grid; grid-template-columns: repeat(3, 22px); gap: 3px; }
#pxe .pxe-anchor .pxe-tab { width: 22px; height: 22px; padding: 0; justify-content: center; }
#pxe .pxe-actions { display: flex; flex-wrap: wrap; gap: 6px; }
#pxe .pxe-groupchecks { display: flex; flex-wrap: wrap; gap: 4px 12px; }
#pxe .pxe-groupchecks .pxe-check { font-size: 12.5px; }
#pxe .pxe-code {
  width: 100%; box-sizing: border-box; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px;
  word-break: break-all;
}
#pxe input[type="file"] { max-width: 100%; box-sizing: border-box; }

#pxe .pxe-help { margin-top: 24px; font-size: 14.5px; line-height: 1.65; max-width: 80ch; }
#pxe .pxe-help p { margin: 0; }
