:root {
  color-scheme: light;
  --page: #f6f5fa;
  --card: #fff;
  --ink: #262238;
  --muted: #696579;
  --line: #e8e5ef;
  --purple: #6d4ce5;
  --purple-dark: #5431cd;
  --tint: #f1ecff;
  --radius: 17px;
  font: 16px/1.5 "Segoe UI", "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--page); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; color: inherit; }
button:disabled { cursor: default; opacity: .43; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 3px;
}
h1, h2, p { margin: 0; }
svg { width: 18px; height: 18px; flex: 0 0 auto; vertical-align: middle; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

.app-header { background: white; border-bottom: 1px solid var(--line); }
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 73px;
  max-width: 1600px;
  padding: 12px clamp(18px, 3.4vw, 56px);
  margin: auto;
}
.brand { display: flex; align-items: center; gap: 11px; font-size: 1.15rem; font-weight: 760; white-space: nowrap; }
.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 7px);
  place-content: center;
  gap: 2px;
  width: 35px;
  height: 35px;
  border-radius: 10px;
  background: var(--purple);
  box-shadow: 0 3px 8px #6d4ce538;
}
.brand-mark i { width: 7px; height: 7px; background: #fff; border-radius: 1px; }
.brand-mark i:last-child { background: #cbbaff; }
.header-actions, .canvas-actions, .brush-settings, .zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  font-size: .875rem;
  font-weight: 650;
  white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s;
}
.button-outline { border-color: var(--line); background: white; }
.button-outline:hover, .button-quiet:hover { background: #eeebf7; border-color: #e4dff2; }
.button-primary { background: var(--purple); color: white; }
.button-primary:hover { background: var(--purple-dark); }
.button-tint { background: var(--tint); color: #5535c5; border-color: #e8dfff; }
.button-tint:hover { background: #e9dfff; }
.button-dark { background: #302841; color: #fff; }
.button-dark:hover { background: #4a3b65; }
.full { width: 100%; }
.icon-button, .text-button, .zoom-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  border-radius: 7px;
  color: var(--muted);
}
.icon-button { padding: 0; width: 32px; height: 32px; }
.icon-button:hover:not(:disabled), .zoom-label:hover, .text-button:hover { background: var(--tint); color: var(--purple-dark); }
.icon-button[aria-pressed="true"] { background: var(--tint); color: var(--purple-dark); }
.text-button { gap: 4px; padding: 4px 5px; font-size: .8125rem; white-space: nowrap; }
.text-button svg { width: 15px; height: 15px; }

.workspace { max-width: 1600px; margin: auto; padding: 27px clamp(18px, 3.4vw, 56px) 18px; }
.workspace-heading { display: flex; align-items: end; justify-content: space-between; gap: 14px; margin-bottom: 20px; }
h1 { font-size: clamp(1.55rem, 2.4vw, 2rem); line-height: 1.25; letter-spacing: -.025em; font-weight: 780; }
.workspace-heading p { color: var(--muted); font-size: .875rem; margin-top: 6px; }
.shortcuts { color: var(--muted); min-height: 35px; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1fr) clamp(305px, 25vw, 350px); gap: 17px; align-items: stretch; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 2px 6px #30284106; }

.canvas-card { display: flex; flex-direction: column; min-width: 0; overflow: hidden; min-height: 665px; }
.canvas-header, .canvas-footer { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 15px; min-height: 51px; }
.canvas-header { border-bottom: 1px solid var(--line); }
.canvas-footer { border-top: 1px solid var(--line); }
.file-info { display: flex; min-width: 0; align-items: center; gap: 9px; font-size: .875rem; }
.file-info strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-icon { color: var(--purple); display: inline-flex; }
.size-tag {
  background: #f3f1f7;
  border-radius: 5px;
  padding: 2px 6px;
  color: #696478;
  font: .75rem/1.5 ui-monospace, Consolas, monospace;
  white-space: nowrap;
}
.canvas-actions { flex-shrink: 0; gap: 3px; }
.vertical-rule { height: 20px; width: 1px; margin: 0 4px; background: var(--line); }
.editor-body { position: relative; flex: 1; display: flex; min-height: 0; }
.tool-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 65px;
  flex: 0 0 auto;
  padding: 11px 6px;
  background: #fff;
  border-right: 1px solid var(--line);
}
.tool-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 50px;
  height: 52px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  font-size: .75rem;
  font-weight: 600;
  color: #625e73;
}
.tool-button svg { width: 19px; height: 19px; }
.tool-button:hover { background: #f5f2fb; }
.tool-button[aria-pressed="true"] { background: var(--tint); border-color: #ece5ff; color: #5736d0; }
.rail-rule { width: 28px; height: 1px; margin: 4px 0; background: var(--line); }
.stage {
  position: absolute;
  inset: 0 0 0 65px;
  overflow: auto;
  isolation: isolate;
  background: radial-gradient(circle, #d9d4e5 1px, transparent 1.2px) 2px 2px / 17px 17px, #efedf5;
  scrollbar-color: #c1b6d4 #edeaf3;
}
.stage-content {
  display: grid;
  place-items: center;
  min-width: 100%;
  min-height: 100%;
  width: max-content;
  height: max-content;
  padding: 25px;
}
.surface {
  position: relative;
  width: 480px;
  height: 400px;
  box-shadow: 0 0 0 1px #68538326, 0 12px 32px #46315f24;
  background: conic-gradient(#e9e5f1 25%, #f9f8fc 0 50%, #e9e5f1 0 75%, #f9f8fc 0) 0 0 / 24px 24px;
  touch-action: none;
  user-select: none;
}
.surface canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
.surface { cursor: crosshair; }
.surface[data-tool="pan"] { cursor: grab; }
.surface.is-panning { cursor: grabbing; }
.pixel-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(to right, #37224c35 1px, transparent 1px), linear-gradient(to bottom, #37224c35 1px, transparent 1px);
  background-size: var(--pixel-width) var(--pixel-height);
}
.drop-hint {
  position: fixed;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #f1ecfff2;
  border: 2px dashed var(--purple);
  color: var(--purple-dark);
  font-weight: 700;
  pointer-events: none;
}
.brush-settings { font-size: .8125rem; color: var(--muted); }
.brush-settings label { flex-shrink: 0; white-space: nowrap; }
.brush-settings .small-select { width: auto; }
.cursor-position, .zoom-label { font-family: ui-monospace, Consolas, monospace; font-variant-numeric: tabular-nums; }
.cursor-position { padding-left: 6px; color: #7a748b; white-space: nowrap; }
.zoom-controls { gap: 2px; padding: 1px 3px; border: 1px solid var(--line); border-radius: 8px; }
.zoom-controls .icon-button { height: 27px; width: 28px; }
.zoom-controls svg { width: 15px; height: 15px; }
.zoom-label { min-width: 54px; min-height: 27px; padding: 2px 5px; font-size: .8125rem; }

.sidebar { display: grid; gap: 15px; align-content: start; min-width: 0; }
.panel { padding: 15px 16px; }
.panel-heading, .panel-title, .swatch-heading, .selected-color, .background-color-row, .background-color-actions, .workspace-footer {
  display: flex;
  align-items: center;
}
.panel-heading, .swatch-heading, .background-color-row { justify-content: space-between; gap: 8px; }
.panel-title { gap: 9px; }
.panel-title h2, .dialog-heading h2 { font-size: 1rem; line-height: 1.3; font-weight: 760; }
.panel-icon { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 9px; }
.panel-icon svg { width: 17px; height: 17px; }
.purple-icon { background: var(--tint); color: var(--purple-dark); }
.green-icon { background: #e5f6ef; color: #218365; }
.palette-settings { display: grid; grid-template-columns: minmax(0, 1fr) 83px; gap: 9px; margin: 12px 0 9px; }
.field { display: grid; align-content: start; gap: 4px; min-width: 0; }
.field label, .range-field label, .background-color-row { font-size: .8125rem; color: #58536a; font-weight: 600; }
select, input:not([type="checkbox"], [type="range"], [type="color"], [type="file"]) {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  border: 1px solid #e3dfee;
  background-color: #fcfbfe;
  color: var(--ink);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: .875rem;
}
select {
  appearance: none;
  padding-right: 26px;
  background: #fcfbfe url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='m3 4.5 3 3 3-3' fill='none' stroke='%23706a80' stroke-width='1.3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 8px center / 12px no-repeat;
}
select.small-select { min-width: 70px; min-height: 30px; padding: 3px 23px 3px 8px; font-size: .8125rem; }
.palette-divider { width: 100%; height: 1px; background: var(--line); margin: 13px 0 6px; }
.swatch-heading { margin-bottom: 4px; }
.swatch-label { font-size: .8125rem; font-weight: 720; }
.swatch-label span { margin-left: 5px; color: var(--muted); font-weight: 500; font-size: .75rem; }
.swatch-heading .icon-button { height: 28px; width: 28px; }
.swatch-heading .icon-button svg { width: 15px; height: 15px; }
.swatches {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  max-height: 198px;
  padding: 3px;
  margin: -3px;
  overflow: auto;
}
.swatch {
  display: grid;
  grid-template-rows: 35px auto;
  min-width: 0;
  padding: 2px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  text-align: center;
}
.swatch:hover { border-color: #ae98ef; }
.swatch[aria-pressed="true"] { outline: 2px solid var(--purple); outline-offset: -1px; }
.swatch-block { border-radius: 5px; background: var(--swatch); }
.swatch code, .selected-color code { font: .68rem/1.55 ui-monospace, Consolas, monospace; color: #575167; white-space: nowrap; }
.swatch code { display: block; padding-top: 2px; overflow: hidden; text-overflow: ellipsis; }
.empty-state { grid-column: 1 / -1; color: var(--muted); font-size: .8125rem; padding: 10px 0; }
.selected-color { min-height: 35px; margin-top: 10px; padding: 5px 8px; gap: 7px; border-radius: 7px; background: #f7f5fb; color: #625c74; font-size: .8125rem; }
.selected-color code { margin-left: auto; font-size: .75rem; }
.active-color-chip { width: 16px; height: 16px; border-radius: 4px; border: 1px solid #22193522; }

.process-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; background: #f4f2f8; padding: 3px; border-radius: 9px; margin: 12px 0 10px; }
.process-tabs button { border: 1px solid transparent; border-radius: 7px; background: transparent; padding: 5px 4px; font-size: .875rem; font-weight: 650; color: var(--muted); }
.process-tabs button:hover { color: var(--purple-dark); }
.process-tabs button[aria-selected="true"] { color: #5535c5; border-color: #e9e4f2; background: #fff; box-shadow: 0 1px 3px #3028410d; }
.background-color-row { min-height: 31px; }
.background-color-actions { gap: 4px; }
.background-color-actions .icon-button { width: 28px; height: 28px; }
.background-color-actions .icon-button svg { width: 15px; height: 15px; }
.color-input-frame { display: grid; place-items: center; width: 28px; height: 28px; border: 1px solid #e3dfee; border-radius: 7px; background: #fff; overflow: hidden; }
input[type="color"] { display: block; width: 100%; height: 100%; padding: 2px; border: 0; background: transparent; cursor: pointer; }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 1px; }
input[type="color"]::-webkit-color-swatch { border: 1px solid #0002; border-radius: 4px; }
.range-field { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 3px 8px; margin: 8px 0; }
.range-field output { color: #5939c8; background: var(--tint); border-radius: 5px; padding: 1px 5px; font: .75rem/1.5 ui-monospace, Consolas, monospace; }
input[type="range"] { grid-column: 1/-1; width: 100%; height: 16px; margin: 0; accent-color: var(--purple); cursor: pointer; }
.range-field:has(input:disabled) { opacity: .55; }
input[type="range"]:disabled { cursor: default; }
.checkbox-field { display: flex; gap: 6px; align-items: center; color: #615b72; font-size: .8125rem; margin: 8px 0 11px; }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--purple); margin: 0; cursor: pointer; }
.cleanup-field { margin: 7px 0 10px; }
#cleanup-options .button-dark { margin-top: 5px; }
.workspace-footer { gap: 6px; justify-content: flex-end; color: #726d80; font-size: .75rem; margin-top: 10px; }
.workspace-footer svg { width: 13px; height: 13px; }

.toast {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 23px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 9px;
  width: max-content;
  max-width: calc(100vw - 32px);
  background: #302841;
  color: white;
  border-radius: 9px;
  padding: 10px 14px;
  font-size: .875rem;
  box-shadow: 0 8px 22px #30284133;
}
dialog {
  width: min(430px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 70px #24193747;
}
dialog::backdrop { background: #29203970; }
.dialog-body { padding: 17px; }
.dialog-heading, .dialog-actions, .library-dialog-controls, .library-name-form, .add-color-form { display: flex; align-items: center; gap: 8px; }
.dialog-heading { justify-content: space-between; margin-bottom: 13px; }
.dialog-heading h2 { font-size: 1.16rem; }
.dialog-actions { margin-top: 14px; justify-content: end; }
.dimension-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.library-dialog { width: min(510px, calc(100vw - 32px)); }
.library-dialog-controls, .library-name-form { margin-bottom: 8px; }
.library-name-form .danger { flex-shrink: 0; color: #a13957; }
.library-name-form .danger.armed { background: #fcebf0; }
.library-colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(43px, 1fr)); gap: 6px; max-height: 270px; overflow: auto; padding: 4px; margin: -4px 0 12px; }
.library-swatch { position: relative; height: 37px; background: var(--swatch); border: 1px solid #0002; border-radius: 6px; }
.library-swatch span { position: absolute; top: 2px; right: 3px; display: grid; place-items: center; width: 16px; height: 16px; border-radius: 5px; background: #231b39ba; color: #fff; font-size: .82rem; line-height: 1; }
.library-swatch:hover { outline: 2px solid var(--purple); outline-offset: 1px; }
.add-color-form .color-input-frame { width: 35px; height: 36px; flex: 0 0 auto; }
.library-feedback { min-height: 18px; margin-top: 5px; color: var(--muted); font-size: .8125rem; }
.shortcut-list { margin: 0; }
.shortcut-list div { display: flex; justify-content: space-between; gap: 8px; align-items: center; border-top: 1px solid var(--line); padding: 8px 0; font-size: .875rem; }
.shortcut-list dd { margin: 0; }
kbd { display: inline-block; background: #f5f3fa; border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; color: #514968; }

@media (min-height: 930px) and (min-width: 1000px) {
  .canvas-card { min-height: min(77vh, 810px); }
}
@media (max-width: 820px) {
  .workspace-grid { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .canvas-card { min-height: clamp(410px, 63vh, 610px); }
  .sidebar { grid-template-columns: 1fr 1fr; align-items: start; }
}
@media (max-width: 550px) {
  .header-inner { padding: 8px 12px; min-height: 56px; gap: 6px; }
  .brand { gap: 5px; font-size: .98rem; }
  .brand-mark { width: 26px; height: 26px; border-radius: 7px; grid-template-columns: repeat(2, 5px); }
  .brand-mark i { width: 5px; height: 5px; }
  .header-actions { gap: 4px; }
  .header-actions .button { min-height: 33px; gap: 4px; padding: 4px 6px; font-size: .75rem; }
  .header-actions svg { width: 14px; height: 14px; }
  .workspace { padding: 17px 10px 12px; }
  .workspace-heading { margin-bottom: 12px; }
  .workspace-heading p { font-size: .8125rem; }
  .canvas-card { min-height: 430px; }
  .canvas-header, .canvas-footer { padding: 6px 8px; min-height: 44px; }
  .tool-rail { position: absolute; z-index: 1; flex-direction: row; width: 100%; height: 46px; gap: 4px; justify-content: center; padding: 4px; border-right: 0; border-bottom: 1px solid var(--line); }
  .tool-button { width: 50px; height: 37px; gap: 1px; font-size: .68rem; }
  .tool-button svg { width: 15px; height: 15px; }
  .rail-rule { height: 19px; width: 1px; margin: 0 3px; }
  .stage { inset: 46px 0 0; }
  .stage-content { padding: 12px; }
  .sidebar { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
