:root {
  --ink: #f4fbff;
  --muted: #90a4c8;
  --bg: #050816;
  --panel: #0d1530;
  --panel-2: #121d3f;
  --line: #52f3ff;
  --line-soft: rgba(82, 243, 255, 0.35);
  --pink: #ff3df2;
  --yellow: #ffe45c;
  --green: #31ff87;
  --shadow: #000;
  --scrollbar-track: rgba(5, 8, 22, 0.82);
  --scrollbar-thumb: #52f3ff;
  --scrollbar-thumb-hover: #ffe45c;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  border: 1px solid rgba(82, 243, 255, 0.22);
  background:
    linear-gradient(90deg, rgba(82, 243, 255, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(255, 61, 242, 0.06) 1px, transparent 1px),
    var(--scrollbar-track);
  background-size: 6px 6px, 6px 6px, auto;
  box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.68);
}

*::-webkit-scrollbar-thumb {
  min-height: 34px;
  min-width: 34px;
  border: 2px solid #050816;
  background:
    linear-gradient(180deg, rgba(244, 251, 255, 0.45), transparent 42%),
    linear-gradient(135deg, var(--scrollbar-thumb), var(--pink));
  box-shadow:
    inset 0 0 0 1px rgba(244, 251, 255, 0.5),
    0 0 10px rgba(82, 243, 255, 0.28);
}

*::-webkit-scrollbar-thumb:hover {
  background:
    linear-gradient(180deg, rgba(244, 251, 255, 0.5), transparent 40%),
    linear-gradient(135deg, var(--scrollbar-thumb-hover), var(--pink));
}

*::-webkit-scrollbar-corner {
  background: #050816;
}

body {
  margin: 0;
  width: 100vw;
  min-width: 1180px;
  height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(82, 243, 255, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(255, 61, 242, 0.07) 1px, transparent 1px),
    radial-gradient(circle at 18% 12%, rgba(255, 61, 242, 0.2), transparent 28%),
    radial-gradient(circle at 82% 72%, rgba(49, 255, 135, 0.14), transparent 30%),
    #050816;
  background-size: 28px 28px, 28px 28px, auto, auto, auto;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.035) 0,
    rgba(255, 255, 255, 0.035) 1px,
    transparent 1px,
    transparent 5px
  );
  mix-blend-mode: screen;
  opacity: 0.3;
}

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

button,
select,
input[type="number"],
textarea,
input[type="color"],
.file-drop {
  border: 2px solid var(--line);
  background: #081027;
  color: var(--ink);
  box-shadow: 3px 3px 0 var(--pink), 0 0 14px rgba(82, 243, 255, 0.16);
}

button {
  min-height: 32px;
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.tools-panel button {
  min-height: 28px;
  padding: 3px 6px;
  font-size: 12px;
}

.tools-panel button[data-tool],
#undoButton,
#redoButton,
#saveProject,
#loadProject {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  white-space: nowrap;
}

.tools-panel button[data-tool] span,
#undoButton span,
#redoButton span,
#saveProject span,
#loadProject span {
  min-width: 0;
  flex: 0 1 auto;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
}

.tools-panel kbd,
#undoButton kbd,
#redoButton kbd,
#saveProject kbd,
#loadProject kbd {
  flex: 0 0 auto;
  margin-left: 0;
  min-width: 18px;
  padding: 1px 3px;
  border: 1px solid rgba(82, 243, 255, 0.62);
  background:
    linear-gradient(180deg, rgba(244, 251, 255, 0.12), rgba(5, 8, 22, 0.45)),
    rgba(5, 8, 22, 0.72);
  color: var(--yellow);
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 8px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  box-shadow: 1px 1px 0 #000;
}

.tools-panel button[data-tool]::before,
#undoButton::before,
#redoButton::before,
#saveProject::before,
#loadProject::before {
  content: "";
  display: block;
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  background: var(--yellow);
  -webkit-mask: var(--tool-icon) center / contain no-repeat;
  mask: var(--tool-icon) center / contain no-repeat;
}

.tools-panel button[data-tool="pan"]::before {
  background: var(--green);
}

.tools-panel button[data-tool="erase"]::before,
.tools-panel button[data-tool="pick"]::before {
  background: var(--line);
}

.tools-panel button[data-tool="place"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15 3l6 6-9 9H7v-5z' fill='none' stroke='black' stroke-width='2.3' stroke-linejoin='round'/%3E%3Cpath d='M5 21c2.2-.2 3.4-1.4 3.6-3.6' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round'/%3E%3C/svg%3E");
}

.tools-panel button[data-tool="erase"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 15l8-8 5 5-8 8H7l-4-4z' fill='none' stroke='black' stroke-width='2.3' stroke-linejoin='round'/%3E%3Cpath d='M12 20h9' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round'/%3E%3C/svg%3E");
}

.tools-panel button[data-tool="pick"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M14 4l6 6-3 3-6-6z' fill='none' stroke='black' stroke-width='2.3' stroke-linejoin='round'/%3E%3Cpath d='M13 9l-8 8v3h3l8-8' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.tools-panel button[data-tool="fill"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 4l11 11-6 6-8-8z' fill='none' stroke='black' stroke-width='2.3' stroke-linejoin='round'/%3E%3Cpath d='M15 15h7v6h-7z' fill='black'/%3E%3Cpath d='M8 7l4-4' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round'/%3E%3C/svg%3E");
}

.tools-panel button[data-tool="line"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 19L19 5' fill='none' stroke='black' stroke-width='2.8' stroke-linecap='round'/%3E%3Ccircle cx='5' cy='19' r='2.4' fill='black'/%3E%3Ccircle cx='19' cy='5' r='2.4' fill='black'/%3E%3C/svg%3E");
}

.tools-panel button[data-tool="rect"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='5' y='6' width='14' height='12' rx='1' fill='none' stroke='black' stroke-width='2.4'/%3E%3C/svg%3E");
}

.tools-panel button[data-tool="pan"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M8 12V5a2 2 0 014 0v5-3a2 2 0 014 0v4-2a2 2 0 014 0v6c0 4-2.7 7-7 7h-2c-3.4 0-5.4-1.8-7-5l-2-4a2 2 0 013.5-1.9L8 14z' fill='none' stroke='black' stroke-width='2.1' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.tools-panel button[data-tool="select"] {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Crect x='5' y='5' width='14' height='14' fill='none' stroke='black' stroke-width='2.2' stroke-dasharray='3 2'/%3E%3Cpath d='M14 14l5 5' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'/%3E%3C/svg%3E");
}

#undoButton {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 7H4v5' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M5 12a8 8 0 111.8 5' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}

#redoButton {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M15 7h5v5' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath d='M19 12a8 8 0 10-1.8 5' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E");
}

#saveProject {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 4h12l2 2v14H5z' fill='none' stroke='black' stroke-width='2.3' stroke-linejoin='round'/%3E%3Cpath d='M8 4v6h8V4M8 20v-6h8v6' fill='none' stroke='black' stroke-width='2.3' stroke-linejoin='round'/%3E%3C/svg%3E");
}

#loadProject {
  --tool-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 7h7l2 3h9v9H3z' fill='none' stroke='black' stroke-width='2.3' stroke-linejoin='round'/%3E%3Cpath d='M12 13v5m0 0l-3-3m3 3l3-3' fill='none' stroke='black' stroke-width='2.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

button:hover,
button.active,
.palette-item.active {
  background: linear-gradient(135deg, rgba(82, 243, 255, 0.34), rgba(255, 61, 242, 0.3));
  box-shadow: 2px 2px 0 var(--yellow), 0 0 18px rgba(255, 61, 242, 0.34);
  transform: translate(1px, 1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

select {
  width: 100%;
  height: 32px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 800;
}

input[type="number"] {
  width: 100%;
  height: 32px;
  padding: 4px 8px;
  font-size: 13px;
  font-weight: 900;
}

input[type="text"] {
  width: 100%;
  height: 32px;
  padding: 4px 8px;
  border: 2px solid var(--line);
  background: #081027;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  box-shadow: 3px 3px 0 var(--pink), 0 0 14px rgba(82, 243, 255, 0.16);
}

textarea {
  width: 100%;
  min-height: 52px;
  resize: vertical;
  padding: 5px 7px;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.tools-panel input[type="text"],
.tools-panel select {
  height: 28px;
  padding: 3px 6px;
  font-size: 12px;
}

input[type="color"] {
  width: 100%;
  height: 32px;
  padding: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(520px, 1fr) 340px;
  gap: 10px;
  height: 100vh;
  padding: 10px;
}

.panel,
.workspace {
  position: relative;
  min-height: 0;
  border: 2px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 34%),
    var(--panel);
  box-shadow:
    5px 5px 0 var(--shadow),
    0 0 0 1px rgba(255, 61, 242, 0.45),
    0 0 24px rgba(82, 243, 255, 0.14);
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  padding: 10px;
}

.tools-panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 8px;
}

.workspace {
  display: grid;
  grid-template-rows: 52px minmax(0, 1fr);
  min-width: 520px;
}

.brand-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 0 0 auto;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--line-soft);
  text-align: center;
}

.pixel-logo {
  display: block;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  background: #050816;
  box-shadow: 3px 3px 0 var(--pink), 0 0 0 2px var(--yellow), 0 0 18px rgba(255, 228, 92, 0.22);
  image-rendering: pixelated;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: var(--yellow);
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  text-shadow: 2px 0 0 var(--pink), -2px 2px 0 #102456;
}

h2 {
  margin: 0 0 6px;
  color: var(--line);
  font-size: 14px;
  font-weight: 900;
}

.tools-panel h2 {
  margin-bottom: 3px;
  font-size: 13px;
}

.compact-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
}

.compact-section-heading h2 {
  margin: 0;
}

.compact-section-heading strong {
  flex: 0 0 auto;
  color: var(--yellow);
  font-size: 11px;
  font-weight: 900;
}

.control-group,
.tools-panel section,
.palette-panel section {
  display: grid;
  gap: 7px;
  margin-bottom: 8px;
}

.tools-panel section {
  flex: 0 0 auto;
  gap: 5px;
  margin-bottom: 6px;
}

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.file-drop {
  display: grid;
  min-height: 32px;
  place-items: center;
  padding: 5px 8px;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.file-drop input {
  display: none;
}

.section-heading,
.canvas-toolbar,
.button-row,
.stats div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-heading span,
.section-heading strong {
  color: var(--yellow);
}

.palette-panel > section:last-child {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  margin-bottom: 0;
}

.palette-manager {
  border-top: 1px solid var(--line-soft);
  padding-top: 7px;
}


.palette-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-content: start;
  gap: 7px;
  min-height: 0;
  overflow: auto;
  border: 2px solid var(--line);
  border-radius: 0 0 8px 8px;
  background:
    linear-gradient(180deg, rgba(255, 228, 92, 0.08), transparent 22%),
    linear-gradient(90deg, rgba(244, 251, 255, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(244, 251, 255, 0.04) 1px, transparent 1px),
    #070e22;
  background-size: auto, 14px 14px, 14px 14px, auto;
  padding: 9px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 61, 242, 0.16),
    inset 0 8px 24px rgba(255, 228, 92, 0.04);
}

.palette-item {
  position: relative;
  display: grid;
  place-items: center;
  aspect-ratio: 1.05;
  min-height: 56px;
  border: 1px solid rgba(221, 232, 243, 0.2);
  border-radius: 5px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.16), rgba(197, 227, 255, 0.05) 36%, rgba(5, 8, 22, 0.2)),
    #11192f;
  color: var(--ink);
  padding: 4px;
  cursor: pointer;
  box-shadow:
    2px 2px 0 rgba(0, 0, 0, 0.56),
    inset 1px 1px 0 rgba(255, 255, 255, 0.18),
    inset -3px -3px 0 rgba(0, 0, 0, 0.38);
}

.palette-item::before {
  content: "";
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(244, 251, 255, 0.08);
  border-radius: 3px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.05),
    inset 0 -3px 0 rgba(3, 7, 18, 0.48);
  pointer-events: none;
}

.palette-item.active {
  border-color: var(--yellow);
  background:
    linear-gradient(135deg, rgba(255, 228, 92, 0.2), rgba(255, 61, 242, 0.16)),
    #17203d;
  box-shadow:
    3px 3px 0 var(--pink),
    0 0 0 2px rgba(255, 228, 92, 0.72),
    0 0 14px rgba(255, 228, 92, 0.28),
    inset 1px 1px 0 rgba(255, 255, 255, 0.24);
}

.palette-item.active::after {
  content: "";
  position: absolute;
  top: -1px;
  right: -1px;
  width: 0;
  height: 0;
  border-top: 12px solid var(--yellow);
  border-left: 12px solid transparent;
  filter: drop-shadow(1px 1px 0 #000);
}

.palette-item > * {
  pointer-events: none;
}

.palette-slot {
  position: relative;
  display: grid;
  width: min(42px, calc(100% - 14px));
  height: min(42px, calc(100% - 14px));
  place-items: center;
  border: 1px solid rgba(244, 251, 255, 0.12);
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 38%),
    rgba(3, 8, 22, 0.5);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.06),
    inset 0 -3px 0 rgba(0, 0, 0, 0.24);
}

.swatch {
  position: relative;
  width: min(32px, 78%);
  height: min(32px, 78%);
  border: 0;
  border-radius: 0;
  clip-path: polygon(50% 0, 92% 25%, 92% 75%, 50% 100%, 8% 75%, 8% 25%);
  filter:
    drop-shadow(0 1px 0 rgba(255, 255, 255, 0.18))
    drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.48));
}

.swatch::after {
  content: none;
  position: absolute;
  inset: 9px;
  border: 1px solid rgba(21, 21, 21, 0.65);
  border-radius: 0;
  clip-path: polygon(50% 0, 92% 25%, 92% 75%, 50% 100%, 8% 75%, 8% 25%);
  background: #10162c;
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.24);
}

.palette-item strong {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: grid;
  min-width: 18px;
  height: 15px;
  place-items: center;
  padding: 1px 4px 0;
  border: 1px solid rgba(244, 251, 255, 0.14);
  border-radius: 3px 0 3px 0;
  background: rgba(5, 8, 22, 0.72);
  color: rgba(244, 251, 255, 0.92);
  font-size: 9px;
  line-height: 1;
  box-shadow: -1px -1px 0 rgba(255, 61, 242, 0.28);
}

.palette-empty {
  grid-column: 1 / -1;
  display: grid;
  min-height: 120px;
  place-items: center;
  border: 2px dashed rgba(82, 243, 255, 0.56);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  background: rgba(5, 8, 22, 0.34);
}

.canvas-toolbar {
  min-height: 52px;
  padding: 7px 12px;
  border-bottom: 2px solid var(--line);
  background: rgba(5, 8, 22, 0.78);
}

.canvas-toolbar p {
  margin: 0 0 3px;
  color: var(--yellow);
  font-size: 13px;
  font-weight: 900;
}

.canvas-toolbar strong {
  font-size: 12px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--line);
  font-size: 12px;
  font-weight: 900;
}

.autosave-status {
  display: inline-flex;
  align-items: center;
  min-width: 74px;
  height: 24px;
  padding: 0 8px;
  border: 1px solid rgba(82, 243, 255, 0.5);
  background: rgba(82, 243, 255, 0.08);
  color: var(--line);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.autosave-status.is-saving {
  border-color: rgba(255, 228, 92, 0.72);
  background: rgba(255, 228, 92, 0.1);
  color: var(--yellow);
}

.autosave-status.is-saved {
  border-color: rgba(49, 255, 135, 0.62);
  background: rgba(49, 255, 135, 0.08);
  color: var(--green);
}

.autosave-status.is-error {
  border-color: rgba(255, 61, 242, 0.78);
  background: rgba(255, 61, 242, 0.1);
  color: var(--pink);
}

.canvas-stage {
  position: relative;
  display: grid;
  justify-items: start;
  align-items: start;
  overflow: auto;
  padding: 12px;
  background:
    linear-gradient(90deg, rgba(82, 243, 255, 0.1) 1px, transparent 1px),
    linear-gradient(rgba(82, 243, 255, 0.1) 1px, transparent 1px),
    radial-gradient(circle at center, rgba(82, 243, 255, 0.16), transparent 52%),
    #070b1d;
  background-size: 18px 18px, 18px 18px, auto, auto;
  cursor: crosshair;
}

.canvas-stage.is-holding-bead canvas {
  cursor: crosshair;
}

.canvas-stage.is-panning {
  cursor: grab;
}

.canvas-stage.is-panning:active {
  cursor: grabbing;
}

.canvas-sizer {
  position: relative;
  box-sizing: content-box;
  width: 720px;
  height: 720px;
  margin: 0;
  border: 2px solid var(--yellow);
  background: #f2f2f2;
  box-shadow:
    7px 7px 0 #000,
    0 0 0 2px var(--pink),
    0 0 24px rgba(82, 243, 255, 0.2);
  will-change: transform;
}

.canvas-sizer.is-empty {
  place-self: center;
  background:
    linear-gradient(90deg, rgba(194, 209, 226, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(194, 209, 226, 0.08) 1px, transparent 1px),
    #071026;
  background-size: 24px 24px, 24px 24px, auto;
}

canvas {
  display: block;
  margin: 0;
  border: 2px solid var(--yellow);
  background: #f2f2f2;
  box-shadow:
    7px 7px 0 #000,
    0 0 0 2px var(--pink),
    0 0 24px rgba(82, 243, 255, 0.2);
  image-rendering: pixelated;
  touch-action: none;
  transform-origin: center center;
  will-change: transform;
}

.canvas-viewport {
  position: sticky;
  left: 0;
  top: 0;
  width: 720px;
  height: 720px;
}

#boardCanvas,
#beadCanvas {
  position: absolute;
  inset: 0;
  margin: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

#boardCanvas {
  pointer-events: none;
}

.canvas-sizer.is-empty #boardCanvas {
  display: none;
}

#beadCanvas {
  z-index: 1;
}

.canvas-stage.is-panning canvas {
  cursor: grab;
}

.canvas-stage.is-panning canvas:active {
  cursor: grabbing;
}

.bead-cursor {
  --cursor-color: #52f3ff;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 30;
  width: 18px;
  height: 18px;
  pointer-events: none;
  opacity: 0;
  transform: translate(10px, 10px);
  transition: opacity 80ms ease;
}

.bead-cursor.is-visible {
  opacity: 1;
}

.cursor-bead {
  position: absolute;
  left: 0;
  top: 0;
  width: 10px;
  height: 10px;
  border: 0;
  background: var(--cursor-color);
  clip-path: polygon(50% 0, 92% 25%, 92% 75%, 50% 100%, 8% 75%, 8% 25%);
  box-shadow: 0 0 7px color-mix(in srgb, var(--cursor-color) 65%, transparent);
}

.pixel-dialog {
  width: min(420px, calc(100vw - 48px));
  padding: 0;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--ink);
  box-shadow:
    5px 5px 0 #000,
    0 0 0 2px var(--pink),
    0 0 28px rgba(82, 243, 255, 0.28);
}

.pixel-dialog::backdrop {
  background:
    linear-gradient(90deg, rgba(82, 243, 255, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(255, 61, 242, 0.08) 1px, transparent 1px),
    rgba(2, 5, 16, 0.78);
  background-size: 24px 24px, 24px 24px, auto;
}

.pixel-dialog__panel {
  display: grid;
  gap: 12px;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent 36%),
    #0d1530;
}

.pixel-dialog h2 {
  margin: 0;
  color: var(--yellow);
  font-size: 20px;
}

.pixel-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.7;
}

.pixel-dialog__actions {
  display: grid;
  grid-template-columns: 1fr 1fr 80px;
  gap: 8px;
}

.color-import-dialog {
  width: min(520px, calc(100vw - 48px));
}

.color-import-dialog .pixel-dialog__actions {
  grid-template-columns: 1fr 96px;
}

.color-import-dialog textarea {
  min-height: 130px;
  max-height: 220px;
  margin: 0;
  resize: vertical;
}

.pattern-preview-dialog {
  width: min(1040px, calc(100vw - 48px));
}

.pattern-preview-dialog .pixel-dialog__actions {
  grid-template-columns: minmax(160px, 1fr) 96px;
}

.pattern-preview-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.pattern-preview-workbench {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  align-items: stretch;
  gap: 14px;
}

.pattern-preview-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 8px;
  padding: 12px;
  border: 2px solid var(--line-soft);
  background: rgba(5, 8, 22, 0.52);
}

.pattern-preview-controls .slider-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
}

.pattern-preview-controls .check-row {
  min-height: 30px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
}

.crop-scale-control {
  display: grid;
  gap: 7px;
  padding-top: 4px;
  border-top: 1px solid var(--line-soft);
}

.crop-scale-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.crop-scale-heading strong {
  color: var(--yellow);
}

.crop-scale-heading button {
  min-height: 26px;
  padding: 3px 7px;
  font-size: 11px;
}

.pattern-preview-grid figure {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  min-height: 420px;
  margin: 0;
  color: var(--line);
  font-size: 12px;
  font-weight: 900;
}

.crop-stage,
.pattern-preview-grid canvas {
  width: 100%;
  height: 392px;
  border: 2px solid var(--line);
  background: #111111;
  box-shadow: 3px 3px 0 #000;
  object-fit: contain;
}

.crop-stage {
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}

.crop-stage:active {
  cursor: grabbing;
}

.crop-stage::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 1px dashed rgba(255, 228, 92, 0.78);
  pointer-events: none;
}

.crop-stage img {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  box-shadow: none;
  object-fit: cover;
  transform: translate(var(--crop-x, 0), var(--crop-y, 0)) scale(var(--crop-scale, 1));
  transform-origin: center;
  user-select: none;
  pointer-events: none;
}

.pattern-preview-grid canvas {
  image-rendering: pixelated;
  background: #f2f2f2;
}

.cursor-bead::after {
  content: none;
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(16, 36, 86, 0.7);
  background: #fffdf1;
  clip-path: polygon(50% 0, 92% 25%, 92% 75%, 50% 100%, 8% 75%, 8% 25%);
}

.tool-grid,
.button-stack,
.slider-grid,
.board-list {
  display: grid;
  gap: 6px;
}

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

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

.button-row {
  margin-top: 3px;
}

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

.selection-actions button {
  min-height: 28px;
  padding-inline: 5px;
  font-size: 12px;
}

.button-row button {
  flex: 1;
}

.mini-options,
.export-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px;
}

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

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

.compact-check {
  min-height: 24px;
  padding: 2px 5px;
  border: 1px solid rgba(82, 243, 255, 0.42);
  background: rgba(8, 16, 39, 0.62);
  font-size: 11px;
}

.nudge-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 5px;
}

.nudge-grid button {
  min-height: 24px;
  padding: 3px 5px;
  font-size: 11px;
}

.view-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.project-library-shell {
  display: grid;
  min-height: 0;
  border: 1px solid rgba(82, 243, 255, 0.62);
  background:
    linear-gradient(90deg, rgba(82, 243, 255, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(82, 243, 255, 0.05) 1px, transparent 1px),
    rgba(5, 8, 22, 0.4);
  background-size: 12px 12px, 12px 12px, auto;
}

.project-library {
  display: grid;
  align-content: start;
  gap: 5px;
  min-height: 0;
  overflow: auto;
  padding: 6px;
}

.project-library button {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 5px 7px;
  font-size: 12px;
  text-align: left;
}

.project-library-thumb {
  width: 38px;
  height: 38px;
  border: 1px solid rgba(82, 243, 255, 0.48);
  background:
    linear-gradient(90deg, rgba(82, 243, 255, 0.08) 1px, transparent 1px),
    linear-gradient(rgba(82, 243, 255, 0.08) 1px, transparent 1px),
    rgba(240, 237, 231, 0.9);
  background-size: 6px 6px, 6px 6px, auto;
  image-rendering: pixelated;
  object-fit: contain;
}

.project-library-thumb--empty {
  display: block;
}

.project-library-meta {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.project-library-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-library small {
  color: var(--yellow);
  font-size: 10px;
}

.project-library-empty {
  display: grid;
  min-height: 100px;
  place-items: center;
  align-content: center;
  gap: 6px;
  border: 1px dashed rgba(82, 243, 255, 0.5);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.project-library-empty strong {
  color: var(--line);
}

.project-library-empty span {
  font-size: 11px;
}

.project-library-dialog {
  width: min(760px, calc(100vw - 48px));
}

.project-library-dialog .pixel-dialog__panel {
  grid-template-rows: auto minmax(340px, 56vh) auto;
}

.project-library-heading strong {
  color: var(--line);
  font-size: 12px;
}

.project-library-dialog .project-library {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 10px;
}

.project-library-dialog .project-library button {
  grid-template-columns: 64px minmax(0, 1fr);
  min-height: 76px;
  padding: 8px;
}

.project-library-dialog .project-library-thumb {
  width: 64px;
  height: 64px;
}

.project-library-dialog .project-library-empty {
  grid-column: 1 / -1;
  min-height: 260px;
}

.project-library-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) 92px;
  gap: 8px;
}

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

.button-stack button:last-child {
  grid-column: 1 / -1;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 0;
  color: var(--ink);
}

.view-options .check-row {
  min-height: 24px;
  justify-content: center;
  padding: 2px 4px;
  border: 1px solid rgba(82, 243, 255, 0.42);
  background: rgba(8, 16, 39, 0.62);
  font-size: 11px;
}

.check-row input {
  width: 15px;
  height: 15px;
  accent-color: var(--pink);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--line);
}

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

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

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

.creation-actions button {
  min-height: 32px;
}

.color-manager {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 72px 72px;
  align-items: end;
  gap: 5px;
}

.color-manager label {
  gap: 2px;
  font-size: 11px;
}

.color-manager input[type="color"] {
  height: 28px;
}

.color-manager input[type="text"] {
  height: 28px;
  padding-inline: 6px;
  font-size: 12px;
  text-transform: uppercase;
}

.color-manager button {
  min-height: 28px;
  padding-inline: 5px;
  font-size: 12px;
}

.slider-grid label {
  color: var(--ink);
}

.slider-grid span {
  color: var(--yellow);
}

.board-list {
  max-height: 68px;
  overflow: hidden;
  border: 2px solid var(--line);
  background: #060a18;
  padding: 6px;
  color: var(--muted);
  font-size: 12px;
}

.board-list div {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px dashed rgba(82, 243, 255, 0.35);
  padding: 2px 0;
}

.meter {
  height: 15px;
  border: 2px solid var(--line);
  background: #060a18;
  box-shadow: inset 0 0 10px rgba(82, 243, 255, 0.2);
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--pink));
}

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

.stats div {
  border-bottom: 1px dashed rgba(82, 243, 255, 0.55);
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

dd {
  margin: 0;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 900;
}

textarea {
  width: 100%;
  min-height: 58px;
  max-height: 58px;
  margin-top: 6px;
  border: 2px solid var(--line);
  background: #060a18;
  color: var(--ink);
  padding: 7px;
  resize: none;
}

textarea::placeholder {
  color: var(--muted);
}

.color-import-dialog textarea {
  display: block;
  min-height: 130px;
  max-height: 220px;
  margin: 0;
  resize: vertical;
}

.message {
  margin: 4px 0 0;
  border: 2px solid var(--yellow);
  background: rgba(255, 228, 92, 0.12);
  color: var(--yellow);
  padding: 7px;
  font-size: 12px;
  font-weight: 900;
  box-shadow: 3px 3px 0 #000;
}

@media (max-height: 820px) {
  .brand-block {
    display: none;
  }

  .app-shell {
    padding: 8px;
  }

  .file-drop {
    min-height: 34px;
  }

  .board-list {
    display: none;
  }
}
