:root {
  --ink: #17171f;
  --panel: #242433;
  --panel-2: #303044;
  --panel-3: #3b3c50;
  --line: #575a72;
  --text: #f5f2de;
  --muted: #b8b6a5;
  --gold: #f4c542;
  --cyan: #55d6be;
  --rose: #f06b6b;
  --green: #7bd66f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #191923;
  background-size: 16px 16px;
  font-family: "Trebuchet MS", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 2px solid #11111a;
  color: var(--text);
  background: var(--panel-3);
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.28), inset 3px 3px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

button:hover {
  filter: brightness(1.12);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button.primary {
  color: #11111a;
  background: var(--gold);
}

#playBtn.is-playing {
  color: #11111a;
  background: var(--gold);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 1fr;
}

.topbar {
  display: none;
  align-items: center;
  justify-content: flex-start;
  padding: 14px 18px;
  border-bottom: 4px solid #11111a;
  background: #20202c;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.side-brand {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 2px solid #11111a;
}

.meta-settings-button {
  margin-left: auto;
  min-width: 64px;
  min-height: 32px;
  padding: 0 10px;
  color: #11111a;
  background: var(--gold);
  font-size: 13px;
  font-weight: 900;
}

.game-select-panel {
  margin-bottom: 14px;
  padding: 8px 10px;
  border: 2px solid #11111a;
  background: var(--panel-2);
}

.game-select-panel select {
  width: 100%;
}

.media-drawer,
.end-event-drawer,
.levels-drawer {
  margin-bottom: 14px;
  border: 2px solid #11111a;
  background: var(--panel-2);
}

.media-drawer summary,
.end-event-drawer summary,
.levels-drawer summary {
  padding: 9px 10px;
  color: var(--text);
  background: #171721;
  cursor: pointer;
  font-weight: 700;
}

.levels-drawer {
  margin-bottom: 12px;
}

.levels-drawer-body {
  padding: 10px;
}

.levels-drawer .level-list {
  margin-bottom: 10px;
}

.levels-drawer .level-actions {
  margin-bottom: 0;
}

.media-library {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 204px;
  overflow: hidden;
  padding: 10px;
}

.media-library.expanded {
  max-height: min(58vh, 640px);
  overflow-y: auto;
}

.media-size-toggle {
  width: calc(100% - 20px);
  min-height: 32px;
  margin: 0 10px 10px;
  font-size: 13px;
}

.media-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px 10px 0;
}

.media-preset-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 98px;
  gap: 8px;
  align-items: end;
  padding: 8px 10px 0;
}

.media-preset-row button {
  min-width: 0;
  padding: 0 8px;
  font-size: 13px;
}

.media-select-field {
  margin-bottom: 0;
}

.end-event-panel {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.end-event-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.end-event-color-field {
  max-width: 122px;
}

.end-event-palette {
  margin-top: 2px;
}

.brand-mark {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  color: #11111a;
  background: var(--cyan);
  border: 4px solid #11111a;
  box-shadow: 5px 5px 0 #000;
  font-size: 24px;
  font-weight: 900;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 21px;
  letter-spacing: 0;
}

.brand-link {
  color: inherit;
  text-decoration: none;
  font-size: 0.9em;
}

h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

h3 {
  font-size: 15px;
  margin-bottom: 8px;
}

.brand p,
.status {
  color: var(--muted);
}

.top-actions,
.tool-grid {
  display: grid;
  gap: 8px;
}

.tool-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.tool-grid button {
  min-width: 0;
  overflow-wrap: anywhere;
}

.icon-button {
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
}

.top-actions {
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  padding: 8px;
  border: 2px solid #000;
  background: #20202c;
}

.stage-actions button {
  min-width: 0;
  min-height: 34px;
  padding: 0 8px;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.build-download-link {
  display: grid;
  place-items: center;
  min-height: 34px;
  padding: 0 8px;
  color: #11111a;
  background: var(--cyan);
  border: 2px solid #11111a;
  box-shadow: inset -3px -3px 0 rgba(0, 0, 0, 0.22), inset 3px 3px 0 rgba(255, 255, 255, 0.16);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.build-download-link[hidden] {
  display: none;
}

.export-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 2px solid #000;
  background: #20202c;
}

.export-panel[hidden] {
  display: none;
}

.export-panel button {
  min-width: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(540px, 1fr) 320px;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.left-panel,
.stage-panel {
  min-width: 0;
  min-height: 0;
  padding: 14px;
}

.left-panel {
  grid-column: 2;
  grid-row: 1;
  background: var(--panel);
  overflow-y: auto;
}

.left-panel {
  border-left: 4px solid #11111a;
}

.stage-panel {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  align-content: start;
  grid-template-rows: auto auto minmax(0, auto) auto;
  gap: 10px;
  overflow-y: auto;
  overflow-x: hidden;
  background: #111119;
}

.stage-panel.is-playing {
  overflow: hidden;
}

.stage-panel.is-playing .piece-editor {
  display: none;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.tab {
  min-width: 0;
  padding: 0 5px;
  font-size: 13px;
}

.tab.active {
  color: #11111a;
  background: var(--cyan);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.demo-list,
.level-list,
.sfx-list,
.entity-list,
.test-results {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.demo-card,
.level-card,
.sfx-card,
.project-card,
.entity-card,
.test-card {
  padding: 10px;
  border: 2px solid #11111a;
  background: var(--panel-2);
}

.project-card + .project-card,
.tool-grid + .project-card,
.status + .project-card {
  margin-top: 10px;
}

.demo-card,
.level-card {
  display: grid;
  gap: 8px;
  align-items: center;
}

.demo-card {
  grid-template-columns: 1fr auto;
}

.level-card {
  grid-template-columns: 42px 78px minmax(0, 1fr);
  grid-template-areas:
    "badge preview name"
    "actions actions actions";
}

.level-card {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(85, 214, 190, .12), transparent 52%),
    #272739;
}

.level-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: var(--cyan);
}

.level-card-side::before {
  background: var(--gold);
}

.level-card-vertical::before {
  background: #b88cff;
}

.level-card-top::before {
  background: var(--green);
}

.demo-card.active,
.level-card.active {
  outline: 3px solid var(--gold);
}

.demo-card small,
.level-card small {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--muted);
  margin-top: 3px;
}

.level-card small span {
  padding: 2px 6px;
  border: 1px solid #11111a;
  background: #171721;
}

.level-card em {
  display: block;
  margin-top: 5px;
  color: #d8d3bc;
  font-size: 12px;
  font-style: normal;
}

.level-card button {
  position: relative;
}

.level-flow-badge {
  grid-area: badge;
  min-width: 0;
  min-height: 42px;
  padding: 0 6px;
  color: #11111a;
  background: var(--gold);
  font-size: 14px;
  font-weight: 900;
}

.level-preview {
  grid-area: preview;
  position: relative;
  z-index: 1;
  display: block;
  width: 78px;
  height: 44px;
  border: 2px solid #11111a;
  background: #111119;
  image-rendering: pixelated;
}

.level-card-name {
  position: relative;
  z-index: 1;
  justify-self: stretch;
  min-width: 0;
  min-height: 30px;
  padding: 0 6px;
  color: var(--text);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  text-align: center;
}

.level-card-name:hover {
  filter: none;
  background: rgba(245, 242, 222, .06);
}

.level-card-name strong {
  display: block;
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-card-type-main {
  grid-area: name;
  position: relative;
  z-index: 1;
  justify-self: stretch;
  min-height: 44px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  text-align: left;
}

.level-card-type-main:hover {
  filter: none;
  background: rgba(245, 242, 222, .06);
}

.level-card-type-main strong {
  display: block;
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-screen-card {
  grid-template-columns: 72px minmax(0, 1fr);
  grid-template-areas: "badge screen";
  background:
    linear-gradient(90deg, rgba(244, 197, 66, .12), transparent 54%),
    #222232;
}

.level-screen-card > div {
  grid-area: screen;
  position: relative;
  z-index: 1;
}

.level-screen-card::before {
  background: var(--cyan);
}

.level-screen-card .level-flow-badge {
  color: #11111a;
  background: var(--cyan);
}

.level-card-actions {
  grid-area: actions;
  position: relative;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.level-card-actions button {
  min-height: 30px;
  padding: 0;
  font-size: 12px;
}

.level-icon-button {
  min-width: 34px;
}

.level-card-actions .delete-level-card {
  color: #f5f2de;
  background: #3b2028;
  border-color: var(--rose);
}

.level-settings-button {
  color: #11111a;
  background: var(--cyan);
}

.wide {
  width: 100%;
}

.tool-grid.three {
  grid-template-columns: repeat(3, 1fr);
  margin-bottom: 10px;
}

.tool-grid.two {
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 10px;
}

.tool-grid.four {
  grid-template-columns: repeat(4, 1fr);
  margin-bottom: 10px;
}

.tool-grid.five {
  grid-template-columns: repeat(5, 1fr);
  margin-bottom: 10px;
}

.paint-tool.active,
.sprite-tool.active,
.tile-pixel-tool.active,
.end-event-tool.active {
  color: #11111a;
  background: var(--gold);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.compact-field {
  margin-bottom: 0;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-field input {
  width: auto;
  min-height: auto;
  margin: 0;
}

.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.58);
}

.confirm-dialog {
  display: grid;
  gap: 12px;
  width: min(380px, 100%);
  padding: 14px;
  border: 3px solid #11111a;
  background: var(--panel-2);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, 0.48);
}

.confirm-dialog h3 {
  margin-bottom: 0;
}

.confirm-dialog p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.confirm-checkbox {
  color: var(--text);
  font-size: 13px;
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.confirm-actions .danger {
  color: #f5f2de;
  background: #3b2028;
  border-color: var(--rose);
}

input,
select,
textarea {
  width: 100%;
  min-height: 36px;
  border: 2px solid #11111a;
  color: var(--text);
  background: #171721;
  padding: 7px 8px;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--cyan);
}

textarea {
  height: 250px;
  resize: vertical;
  font-family: "Courier New", monospace;
  font-size: 13px;
  line-height: 1.35;
}

#entityScriptInput {
  height: 150px;
}

#spriteScriptInput {
  height: 130px;
}

#endEventScriptInput {
  height: 130px;
}

#tileScriptInput {
  height: 68px;
}

#gameCanvas,
#spriteCanvas,
#tileCanvas,
#endEventCanvas {
  width: 100%;
  image-rendering: pixelated;
  border: 4px solid #000;
  background: #0d0d14;
}

#gameCanvas {
  display: block;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  box-sizing: border-box;
  aspect-ratio: 16 / 9;
  height: 100%;
  max-height: none;
  object-fit: contain;
}

.game-board-row {
  position: relative;
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 40px;
  column-gap: 8px;
  row-gap: 0;
  align-items: stretch;
  height: min(max(300px, calc((100vw - 488px) * .5625 + 40px)), var(--game-max-height, calc(100vh - 118px)), 580px);
  min-height: 0;
}

.hud-palette {
  position: fixed;
  z-index: 60;
  top: 118px;
  right: 86px;
  display: grid;
  gap: 7px;
  width: min(286px, calc(100vw - 32px));
  padding: 8px;
  border: 2px solid #11111a;
  background: rgba(23, 23, 31, .78);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .22);
  backdrop-filter: blur(2px);
}

.level-settings-palette {
  position: fixed;
  z-index: 62;
  top: 132px;
  right: 92px;
  display: grid;
  gap: 8px;
  width: min(276px, calc(100vw - 32px));
  padding: 8px;
  border: 2px solid #11111a;
  background: rgba(32, 32, 44, .9);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .24);
  backdrop-filter: blur(2px);
}

.project-meta-palette {
  position: fixed;
  z-index: 63;
  top: 124px;
  right: 104px;
  display: grid;
  gap: 8px;
  width: min(286px, calc(100vw - 32px));
  padding: 8px;
  border: 2px solid #11111a;
  background: rgba(32, 32, 44, .92);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .26);
  backdrop-filter: blur(2px);
}

.sprite-edit-palette {
  position: fixed;
  z-index: 64;
  top: 116px;
  left: 96px;
  display: grid;
  gap: 8px;
  width: min(326px, calc(100vw - 32px));
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  padding: 8px;
  border: 2px solid #11111a;
  background: rgba(32, 32, 44, .94);
  box-shadow: 0 10px 0 rgba(0, 0, 0, .28);
  backdrop-filter: blur(2px);
}

.hud-palette.collapsed {
  display: none;
}

.level-settings-palette.collapsed {
  display: none;
}

.project-meta-palette.collapsed {
  display: none;
}

.sprite-edit-palette.collapsed {
  display: none;
}

.hud-palette-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding-bottom: 5px;
  border-bottom: 2px solid rgba(245, 242, 222, .22);
  cursor: move;
  user-select: none;
}

.sprite-edit-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding-bottom: 5px;
  border-bottom: 2px solid rgba(245, 242, 222, .22);
  cursor: move;
  user-select: none;
}

.level-settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding-bottom: 5px;
  border-bottom: 2px solid rgba(245, 242, 222, .22);
  cursor: move;
  user-select: none;
}

.project-meta-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding-bottom: 5px;
  border-bottom: 2px solid rgba(245, 242, 222, .22);
  cursor: move;
  user-select: none;
}

.hud-palette-header strong {
  font-size: 13px;
}

.level-settings-header strong {
  font-size: 13px;
}

.project-meta-header strong {
  font-size: 13px;
}

.sprite-edit-header strong {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-palette-header button {
  min-width: 32px;
  min-height: 26px;
  padding: 0 8px;
  background: #3b2028;
  border-color: var(--rose);
}

.level-settings-header button {
  min-width: 32px;
  min-height: 26px;
  padding: 0 8px;
  background: #3b2028;
  border-color: var(--rose);
}

.project-meta-header button {
  min-width: 32px;
  min-height: 26px;
  padding: 0 8px;
  background: #3b2028;
  border-color: var(--rose);
}

.sprite-edit-header button {
  min-width: 32px;
  min-height: 26px;
  padding: 0 8px;
  background: #3b2028;
  border-color: var(--rose);
}

.level-settings-palette .field {
  gap: 4px;
  margin-bottom: 0;
}

.project-meta-palette .field {
  gap: 4px;
  margin-bottom: 0;
}

.level-settings-palette input,
.level-settings-palette select {
  min-height: 30px;
  padding: 5px 7px;
}

.project-meta-palette input,
.project-meta-palette select {
  min-height: 30px;
  padding: 5px 7px;
}

.sprite-edit-palette .field {
  gap: 4px;
  margin-bottom: 0;
}

.sprite-edit-palette input,
.sprite-edit-palette select,
.sprite-edit-palette textarea {
  min-height: 30px;
  padding: 5px 7px;
}

.sprite-edit-palette textarea {
  height: 92px;
  min-height: 72px;
  font-size: 12px;
}

.sprite-edit-palette .project-card {
  margin: 0;
  padding: 8px;
}

.sprite-edit-palette .tool-grid {
  margin-bottom: 0;
}

.hud-palette textarea {
  height: 62px;
  min-height: 62px;
  font-size: 12px;
}

.hud-stats-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.hud-stats-fields[hidden] {
  display: none;
}

.hud-palette .field {
  gap: 4px;
  margin-bottom: 0;
}

.hud-palette input,
.hud-palette textarea {
  min-height: 30px;
  padding: 5px 7px;
}

.hud-palette-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.hud-palette .status {
  font-size: 11px;
  line-height: 1.25;
}

#spriteCanvas {
  aspect-ratio: 1;
  width: min(100%, 256px);
  justify-self: center;
  margin-bottom: 10px;
}

#endEventCanvas {
  aspect-ratio: 1;
}

#tileCanvas {
  aspect-ratio: 1;
  width: min(100%, 176px);
  justify-self: center;
}

.piece-editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "parallax";
  gap: 8px;
  align-items: start;
}

.level-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 148px;
  gap: 6px;
  padding: 4px 6px;
  margin: 0;
  align-items: center;
  border: 2px solid #000;
  background: #20202c;
}

.game-board-row > .level-strip {
  grid-column: 2;
  grid-row: 2;
  min-height: 40px;
  margin-top: -2px;
  border-top-color: #11111a;
}

.level-strip .field {
  margin-bottom: 0;
}

.level-scroll-field {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 24px;
  gap: 4px;
  align-items: center;
}

.level-scroll-field input {
  width: 100%;
}

.level-length-field {
  display: grid;
  grid-template-columns: 24px minmax(44px, 1fr) 24px;
  gap: 4px;
  align-items: center;
}

.level-strip button {
  min-width: 0;
  min-height: 28px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
}

#levelLengthInput {
  min-height: 28px;
  padding: 2px 4px;
  text-align: center;
}

.screen-flow-strip {
  display: none;
}

.screen-flow {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
  white-space: nowrap;
}

.screen-flow button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border: 2px solid #11111a;
  background: var(--panel-2);
}

.screen-flow button.active {
  color: #11111a;
  background: var(--gold);
}

.screen-flow button.delete-flow-level {
  min-width: 42px;
  padding: 0 10px;
  color: #f5f2de;
  background: #3b2028;
  border-color: var(--rose);
}

.screen-flow button.add-flow-level {
  min-width: 42px;
  padding: 0 10px;
  color: #11111a;
  background: var(--cyan);
}

.screen-flow button.add-flow-choice {
  min-width: 78px;
  padding: 0 10px;
  color: #11111a;
  background: #55d6be;
}

.screen-flow button.move-flow-level {
  min-width: 34px;
  padding: 0 8px;
}

.piece-tray {
  grid-column: 1;
  grid-row: 1 / 3;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-columns: 50px;
  justify-content: center;
  width: 62px;
  gap: 4px;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

.piece-tray-scroll {
  display: grid;
  grid-template-columns: 50px;
  gap: 4px;
  align-content: start;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: none;
}

.piece-tray-scroll::-webkit-scrollbar {
  display: none;
}

.piece-button {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 50px;
  padding: 4px;
  color: var(--muted);
  border: 2px solid #000;
  background: #20202c;
}

.piece-button.active {
  color: #11111a;
  background: var(--gold);
}

.piece-scroll-button {
  z-index: 2;
  min-height: 23px;
  height: 23px;
  padding: 0;
  color: var(--text);
  background: var(--panel-2);
}

.delete-piece-button.active {
  background: #3b2028;
  outline: 3px solid var(--rose);
}

.delete-piece-button {
  min-height: 60px;
  padding-block: 6px;
}

.add-piece-button {
  color: #11111a;
  background: #244742;
}

.all-blocks-button {
  color: #11111a;
  background: #243a47;
}

.delete-piece-preview,
.add-piece-preview,
.all-blocks-preview {
  background: #171721;
}

.piece-preview,
.tile-preview {
  display: block;
  width: 30px;
  height: 30px;
  border: 2px solid #000;
  image-rendering: pixelated;
}

.piece-label {
  display: none;
}

.piece-properties {
  position: fixed;
  z-index: 40;
  top: 96px;
  left: 22px;
  right: auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  width: min(540px, calc(100vw - 28px));
  max-height: min(74vh, 560px);
  padding: 4px;
  align-content: start;
  overflow-y: auto;
  border: 2px solid #000;
  background: #20202c;
  box-shadow: 0 12px 0 rgba(0, 0, 0, .28);
}

.piece-properties.collapsed {
  display: none;
}

.block-library-palette {
  position: fixed;
  z-index: 45;
  left: 92px;
  top: 150px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(460px, calc(100vw - 112px));
  height: min(420px, calc(100vh - 180px));
  min-width: 240px;
  min-height: 190px;
  overflow: hidden;
  resize: both;
  border: 2px solid #000;
  background: rgba(32, 32, 44, .78);
  box-shadow: 0 12px 0 rgba(0, 0, 0, .28);
  backdrop-filter: blur(2px);
}

.block-library-palette.collapsed {
  display: none;
}

.block-library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  padding: 4px 6px;
  border-bottom: 2px solid #11111a;
  background: rgba(17, 17, 26, .82);
  cursor: move;
  user-select: none;
}

.block-library-header button {
  min-width: 34px;
  min-height: 26px;
  padding: 0 8px;
  color: #f5f2de;
  background: #3b2028;
  border-color: var(--rose);
}

.block-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.block-library-button {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-height: 44px;
  padding: 4px;
  background: rgba(23, 23, 33, .82);
}

.block-library-button.active {
  outline: 3px solid var(--gold);
}

.block-library-button canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.block-palette-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 26px;
  padding: 0;
  border-bottom: 2px solid #11111a;
  cursor: move;
  user-select: none;
}

.block-palette-header button {
  min-width: 34px;
  min-height: 26px;
  padding: 0 8px;
  color: #f5f2de;
  background: #3b2028;
  border-color: var(--rose);
}

.piece-properties button {
  align-self: end;
}

.piece-properties .field {
  gap: 3px;
  margin-bottom: 3px;
}

.piece-properties .compact-field {
  margin-bottom: 0;
}

.piece-properties .tool-grid {
  gap: 6px;
}

.piece-properties .tool-grid.three,
.piece-properties .tool-grid.two,
.piece-properties .tool-grid.four,
.piece-properties .tool-grid.five {
  margin-bottom: 3px;
}

.piece-properties input,
.piece-properties select {
  min-height: 30px;
  padding: 4px 6px;
}

.parallax-editor {
  grid-area: parallax;
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 2px solid #000;
  background: #20202c;
}

.parallax-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.parallax-header h3 {
  margin-bottom: 0;
}

.parallax-header-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.parallax-header button {
  min-width: 104px;
}

.parallax-editor.collapsed .parallax-track {
  display: none;
}

.parallax-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
  overflow-x: auto;
  padding: 4px;
  border: 2px solid #11111a;
  background: var(--panel-2);
}

.parallax-toolbar button {
  flex: 0 0 auto;
  min-width: 78px;
  min-height: 34px;
}

.parallax-template-select {
  flex: 0 0 154px;
  margin-left: auto;
  min-height: 34px;
}

.parallax-toolbar .parallax-add-layer {
  min-width: 96px;
}

.parallax-visibility-toggle {
  min-width: 92px;
}

.parallax-track {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 4px;
}

.warp-map-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 8px;
  padding: 8px;
  border: 2px solid #11111a;
  background: var(--panel-2);
}

#warpMapCanvas {
  display: block;
  width: 100%;
  height: auto;
  min-height: 180px;
  image-rendering: pixelated;
  border: 2px solid #000;
  background: #111119;
  cursor: crosshair;
}

.warp-inspector {
  display: grid;
  gap: 6px;
  align-content: start;
}

.warp-destination-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.warp-map-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.parallax-card {
  display: grid;
  grid-template-columns: 168px minmax(0, 1fr);
  gap: 7px;
  padding: 8px;
  border: 2px solid #11111a;
  background: var(--panel-2);
}

.parallax-card .field {
  margin-bottom: 0;
}

.parallax-layer-rail {
  display: grid;
  gap: 6px;
  align-content: start;
}

.parallax-layer-rail button {
  min-width: 0;
  min-height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.parallax-order-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.parallax-layer-tool-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.parallax-layer-tool-row button {
  padding: 0 4px;
}

.parallax-array-row {
  display: grid;
  grid-template-columns: 58px 58px 40px;
  gap: 3px;
  align-items: center;
}

.parallax-array-row label,
.parallax-size-row label {
  position: relative;
  display: block;
}

.parallax-array-row label::before,
.parallax-size-row label::before {
  content: attr(data-input-label);
  position: absolute;
  top: 4px;
  left: 6px;
  z-index: 1;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
}

.parallax-array-row input,
.parallax-size-row input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 13px 6px 5px;
  font-size: 15px;
  text-align: center;
}

.parallax-array-row input {
  min-height: 34px;
  padding: 12px 4px 3px;
  font-size: 13px;
}

.parallax-array-apply {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 34px;
  padding: 0;
  border: 2px solid #11111a;
  color: #11111a;
  background: var(--green);
  font-size: 20px;
  font-weight: 900;
  line-height: 1;
}

.parallax-size-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
}

.parallax-grid-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}

.parallax-grid-scroll {
  min-width: 0;
  max-height: 320px;
  overflow-x: auto;
  overflow-y: auto;
  border: 2px solid #11111a;
  background: #111119;
}

.parallax-grid-canvas {
  display: block;
  min-width: 100%;
  height: auto;
  image-rendering: pixelated;
  cursor: crosshair;
}

.parallax-speed-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 4px;
  align-items: center;
  overflow: hidden;
}

.parallax-speed-row button {
  min-width: 0;
  min-height: 34px;
  padding: 0;
  font-size: 16px;
  font-weight: 900;
}

.parallax-speed-row label {
  position: relative;
  margin: 0;
}

.parallax-speed-row label::before {
  content: attr(data-input-label);
  position: absolute;
  top: 4px;
  left: 6px;
  z-index: 1;
  color: var(--muted);
  font-size: 9px;
  line-height: 1;
  pointer-events: none;
}

.parallax-speed-row input {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 12px 4px 3px;
  text-align: center;
}

.parallax-layer-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 4px;
}

.parallax-layer-actions button {
  min-height: 30px;
  padding: 0 4px;
  font-size: 11px;
}

.parallax-layer-actions .danger {
  color: #f5f2de;
  background: #3b2028;
  border-color: var(--rose);
}

.parallax-color-square {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 2px;
}

.parallax-tool.active {
  color: #11111a;
  background: var(--gold);
}

.tile-pixel-editor {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(176px, .9fr) minmax(210px, 1.1fr);
  gap: 4px;
  align-items: start;
}

.tile-animation-card {
  grid-column: 2;
  grid-row: 1 / span 5;
  margin-top: 0;
  padding: 6px;
}

.tile-animation-card h3 {
  margin-bottom: 3px;
}

.tile-script-field {
  margin-top: 4px;
  margin-bottom: 3px;
}

.tile-script-actions {
  margin-bottom: 0;
}

.tile-pixel-editor .color-row,
.tile-color-field,
.tile-tool-row,
.tile-options-row,
#tileCanvas {
  grid-column: 1;
}

.sprite-options-row {
  display: grid;
  grid-template-columns: minmax(54px, .9fr) minmax(70px, 1fr) minmax(54px, .8fr);
  gap: 5px;
  align-items: center;
  margin: 6px 0;
}

.tile-tool-row {
  gap: 3px;
}

.tile-tool-row button {
  min-width: 0;
  min-height: 30px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.tile-options-row {
  display: grid;
  grid-template-columns: minmax(50px, .9fr) minmax(58px, 1fr) 32px 32px;
  gap: 4px;
  align-items: center;
  margin-bottom: 3px;
}

.tile-options-row .checkbox-field,
.sprite-options-row .checkbox-field,
.pixel-size-tag {
  justify-content: center;
  min-height: 30px;
  padding: 0 5px;
  border: 2px solid #11111a;
  background: var(--panel-3);
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
}

.tile-options-row input[type="checkbox"],
.sprite-options-row input[type="checkbox"] {
  margin: 0;
}

.tile-brush-size select,
.sprite-brush-size select {
  min-height: 30px;
  padding: 2px 4px;
  font-size: 12px;
}

.pixel-size-tag {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.tile-mini-action {
  min-width: 0;
  min-height: 30px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
}

.tile-color-field {
  max-width: 58px;
}

#tileColorInput {
  min-height: 38px;
  padding: 2px;
}

.color-row {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 5px;
  margin-bottom: 6px;
}

.tileset {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.sprite-chip {
  display: grid;
  place-items: center;
  gap: 4px;
  height: 88px;
  min-height: 88px;
  padding: 5px;
  color: var(--muted);
  font-size: 11px;
  border: 2px solid #11111a;
  background: #171721;
  overflow: hidden;
}

.sprite-chip span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sprite-chip canvas {
  width: 44px;
  height: 44px;
  image-rendering: pixelated;
}

.sprite-chip:hover {
  color: var(--text);
  outline: 2px solid var(--cyan);
}

.sprite-chip.active {
  color: var(--text);
  outline: 3px solid var(--gold);
}

.swatch,
.tile-button {
  aspect-ratio: 1;
  min-height: 0;
}

.swatch.active,
.tile-button.active {
  outline: 3px solid var(--text);
}

.tile-button {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 4px;
}

.tile-button canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

.frame-chip {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 2px solid #11111a;
  background: #171721;
  color: var(--muted);
}

.frame-chip.active {
  color: #11111a;
  background: var(--green);
}

.frame-chip canvas {
  width: 34px;
  height: 34px;
  image-rendering: pixelated;
}

.entity-card,
.test-card {
  display: grid;
  gap: 4px;
  color: var(--muted);
}

.entity-card {
  grid-template-columns: 44px minmax(0, 1fr);
  align-items: center;
  text-align: left;
}

.entity-preview {
  width: 40px;
  height: 40px;
  border: 2px solid #11111a;
  image-rendering: pixelated;
  background: #171721;
}

.entity-summary {
  min-width: 0;
}

.entity-summary small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.entity-card.active {
  outline: 3px solid var(--cyan);
}

.entity-card strong,
.test-card strong {
  color: var(--text);
}

.test-card.pass {
  border-color: var(--green);
}

.test-card.warn {
  border-color: var(--gold);
}

.test-card.fail {
  border-color: var(--rose);
}

ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}

@media (max-width: 1100px) {
  body {
    overflow: auto;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 300px;
    height: auto;
    overflow: visible;
  }

  .left-panel {
    overflow-y: visible;
  }

  .piece-properties {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  html,
  body {
    height: auto;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    display: block;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    grid-template-columns: repeat(2, 1fr);
  }

  .export-panel {
    grid-template-columns: repeat(2, 1fr);
  }

  .workspace {
    display: block;
    height: auto;
    overflow: visible;
  }

  .left-panel,
  .stage-panel {
    border: 0;
    border-bottom: 4px solid #11111a;
    overflow: visible;
  }

  .piece-editor {
    grid-template-columns: 1fr;
    grid-template-areas:
      "parallax";
  }

  .piece-properties {
    top: 12px;
    right: 12px;
    left: 12px;
    width: auto;
    max-height: calc(100vh - 24px);
  }

  .tile-pixel-editor {
    grid-template-columns: 1fr;
  }

  .tile-animation-card,
  .tile-script-field,
  .tile-pixel-editor > .tool-grid.two,
  .tile-pixel-editor .color-row,
  .tile-color-field,
  .tile-tool-row,
  .tile-options-row,
  #tileCanvas {
    grid-column: 1;
    grid-row: auto;
  }

  .game-board-row {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: auto;
  }

  .game-board-row > .level-strip {
    grid-column: auto;
    grid-row: auto;
    min-height: auto;
    margin-top: 0;
  }

  #gameCanvas {
    grid-column: auto;
    grid-row: auto;
    height: auto;
    object-fit: contain;
  }

  .piece-tray {
    grid-column: auto;
    grid-row: auto;
    grid-template-rows: 46px;
    grid-template-columns: 46px 23px minmax(0, 1fr) 23px 46px;
    justify-content: start;
    width: 100%;
    max-height: 58px;
    overflow: hidden;
  }

  .piece-tray-scroll {
    grid-auto-flow: column;
    grid-auto-columns: 46px;
    grid-template-columns: none;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .piece-scroll-button {
    width: 23px;
    min-width: 23px;
    height: 46px;
    min-height: 46px;
  }

  .block-library-palette {
    left: 12px;
    top: 72px;
    width: calc(100vw - 24px);
    height: min(62vh, 420px);
  }

  .level-settings-palette {
    left: 12px;
    right: auto;
    top: 72px;
    width: calc(100vw - 24px);
  }

  .project-meta-palette {
    left: 12px;
    right: auto;
    top: 72px;
    width: calc(100vw - 24px);
  }

  .level-strip {
    grid-template-columns: 1fr;
  }

  .parallax-card {
    grid-template-columns: 1fr;
  }

  .warp-map-card {
    grid-template-columns: 1fr;
  }

  .parallax-layer-rail {
    grid-template-columns: 72px minmax(0, 1fr) minmax(140px, 1fr);
    align-items: center;
  }

  .tool-grid.four,
  .tool-grid.five {
    grid-template-columns: repeat(2, 1fr);
  }
}
