:root {
  color-scheme: dark;
  --bg: #0d1015;
  --surface: #151a22;
  --surface-2: #1b222d;
  --surface-3: #222b38;
  --border: #303a48;
  --border-soft: #252e3a;
  --text: #f2f5f8;
  --muted: #93a0b1;
  --accent: #ff8a3d;
  --accent-2: #ffb36f;
  --cyan: #74d2df;
  --danger: #f36f70;
  --shadow: 0 16px 50px rgba(0, 0, 0, .35);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f9fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f2f4f6;
  --border: #cfd6de;
  --border-soft: #e7ebf0;
  --text: #191c1e;
  --muted: #5c6270;
  --accent: #111827;
  --accent-2: #000000;
  --cyan: #45464d;
  --danger: #dc2626;
  --shadow: 0 16px 46px rgba(15, 23, 42, .16);
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  display: grid;
  grid-template-rows: 68px minmax(0, 1fr) 46px;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}

button,
select,
input { font: inherit; }

button { color: inherit; }

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

.topbar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(410px, 1fr) minmax(420px, auto);
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(20, 25, 33, .98);
  box-shadow: 0 4px 24px rgba(0, 0, 0, .25);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 2px solid #17202a;
  border-radius: 8px;
  background:
    linear-gradient(45deg, rgba(255,255,255,.16) 25%, transparent 25%, transparent 75%, rgba(255,255,255,.16) 75%),
    linear-gradient(45deg, rgba(255,255,255,.16) 25%, var(--accent) 25%, var(--accent) 75%, rgba(255,255,255,.16) 75%);
  background-position: 0 0, 6px 6px;
  background-size: 12px 12px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.08);
}

.brand div { min-width: 0; }
.brand strong { display: block; font-size: 16px; letter-spacing: .02em; }
.brand span:not(.brand-mark) { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }

.canvas-size-editor,
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.canvas-size-editor {
  min-width: 0;
  justify-content: center;
}

.canvas-size-editor > label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.topbar-label {
  color: #cdd5df;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.dimension-times { color: var(--muted); }

.top-actions { justify-content: flex-end; }

select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 32px 0 10px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  background: var(--surface-2);
}

select:focus,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.button,
.icon-button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .15s ease, opacity .15s ease;
}

.button { padding: 0 13px; white-space: nowrap; }
.button:hover:not(:disabled), .icon-button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: .4; }
.button.primary { color: #25140a; background: var(--accent); font-weight: 750; }
.button.primary:hover { background: var(--accent-2); }
.button.secondary { border-color: var(--border); background: var(--surface-3); }
.button.secondary:hover { border-color: #465568; background: #283342; }
.button.ghost { border-color: var(--border-soft); background: transparent; color: #cdd5df; }
.button.ghost:hover { border-color: var(--border); background: var(--surface-2); }
.button.wide { width: 100%; }
.button kbd { margin-left: 8px; }

.number-control {
  position: relative;
  display: block;
  min-width: 0;
  height: 32px;
}

.number-control input[type="number"] {
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0 27px 0 8px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  background: var(--surface-3);
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}

.number-control input[type="number"]::-webkit-inner-spin-button,
.number-control input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
}

.compact-number-control {
  width: 82px;
  height: 36px;
}

.number-stepper {
  position: absolute;
  top: 1px;
  right: 1px;
  bottom: 1px;
  display: grid;
  grid-template-rows: 1fr 1fr;
  width: 24px;
  overflow: hidden;
  border-left: 1px solid var(--border);
  border-radius: 0 6px 6px 0;
}

.number-stepper button {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  color: #cbd4df;
  border: 0;
  background: #293443;
  cursor: pointer;
  font-size: 8px;
  line-height: 1;
}

.number-stepper button + button { border-top: 1px solid var(--border); }
.number-stepper button:hover { color: #fff; background: #354356; }

.top-history-button {
  flex: 0 0 auto;
  font-size: 20px;
  line-height: 1;
}

.app-shell {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 286px;
  min-height: 0;
}

.toolbox {
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 9px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
}

.tool {
  position: relative;
  display: grid;
  place-items: center;
  gap: 3px;
  min-height: 64px;
  padding: 7px 5px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}

.tool:hover { color: var(--text); background: var(--surface-2); }
.tool:disabled { cursor: not-allowed; opacity: .3; }
.tool:disabled:hover { color: var(--muted); background: transparent; }
.tool.active { color: var(--accent-2); border-color: rgba(255, 138, 61, .34); background: rgba(255, 138, 61, .11); }
.tool-icon { display: grid; place-items: center; width: 22px; height: 22px; font-size: 20px; line-height: 1; }
.tool-icon svg { display: block; width: 21px; height: 21px; }
.select-icon { border: 2px dashed currentColor; border-radius: 2px; }
.tool > span:nth-child(2) { font-size: 12px; }
.tool kbd { position: absolute; top: 5px; right: 6px; opacity: .5; }
.tool-divider { height: 1px; margin: 4px 5px; flex: 0 0 auto; background: var(--border-soft); }
.action-tool { min-height: 52px; }
.action-tool .tool-icon { font-size: 18px; }
.danger-action:not(:disabled) { color: #e7a0a0; }
.danger-action:hover:not(:disabled) { color: #ffd1d1; background: rgba(243, 111, 112, .1); }

kbd {
  color: var(--muted);
  font-family: inherit;
  font-size: 9px;
  font-weight: 700;
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background-color: #0f1319;
  background-image:
    linear-gradient(rgba(255,255,255,.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.018) 1px, transparent 1px);
  background-size: 24px 24px;
}

.workspace.drag-over::after {
  content: "松开以载入图片";
  position: fixed;
  inset: 82px 304px 46px 100px;
  z-index: 20;
  display: grid;
  place-items: center;
  color: var(--text);
  border: 2px dashed var(--accent);
  border-radius: 14px;
  background: rgba(13, 16, 21, .88);
  font-size: 22px;
  font-weight: 750;
  pointer-events: none;
}

.canvas-wrap {
  position: relative;
  width: 1px;
  height: 1px;
  margin: 54px;
  box-shadow: var(--shadow), 0 0 0 1px rgba(255,255,255,.18);
  background-color: #d7dce2;
  background-image:
    linear-gradient(45deg, #aeb6c0 25%, transparent 25%, transparent 75%, #aeb6c0 75%),
    linear-gradient(45deg, #aeb6c0 25%, transparent 25%, transparent 75%, #aeb6c0 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
  transform-origin: top left;
}

.canvas-wrap canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#artCanvas { pointer-events: none; }
#overlayCanvas { touch-action: none; }
#overlayCanvas[data-cursor="crosshair"] { cursor: crosshair; }
#overlayCanvas[data-cursor="move"] { cursor: move; }
#overlayCanvas[data-cursor="fill"] { cursor: cell; }
#overlayCanvas[data-cursor="eyedropper"] {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'%3E%3Cpath d='m19.5 2.5 2 2a2 2 0 0 1 0 2.8l-10 10-4.8-4.8 10-10a2 2 0 0 1 2.8 0Z' fill='white' stroke='%23101820' stroke-width='2' stroke-linejoin='round'/%3E%3Cpath d='m5.8 13.4-3.3 7.8 7.8-3.3' fill='white' stroke='%23101820' stroke-width='2' stroke-linejoin='round'/%3E%3Cpath d='m14.4 4.8 4.8 4.8' stroke='%23101820' stroke-width='2'/%3E%3C/svg%3E") 3 21, crosshair;
}

.selection-outline {
  position: absolute;
  z-index: 3;
  box-sizing: border-box;
  border: 1px dashed rgba(255, 255, 255, .96);
  outline: 1px dashed rgba(10, 15, 22, .95);
  background: rgba(116, 210, 223, .12);
  pointer-events: none;
}

.canvas-wrap[data-active-tool="select"] .selection-outline {
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}

.canvas-resize-handle {
  position: absolute;
  z-index: 4;
  width: 6px;
  height: 6px;
  box-sizing: border-box;
  border: 1px solid rgba(255, 255, 255, .92);
  border-radius: 1px;
  background: var(--accent);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .72);
  touch-action: none;
  user-select: none;
}

.canvas-resize-handle:hover,
.canvas-resize-handle.dragging {
  background: #b9f5ff;
  box-shadow: 0 0 0 1px rgba(116, 210, 223, .34), 0 2px 6px rgba(0, 0, 0, .8);
}

.canvas-resize-handle-x {
  right: -3px;
  top: 50%;
  transform: translateY(-50%);
  cursor: ew-resize;
}

.canvas-resize-handle-y {
  bottom: -3px;
  left: 50%;
  transform: translateX(-50%);
  cursor: ns-resize;
}

.empty-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-hint[hidden] { display: none; }
.empty-hint strong { color: var(--text); font-size: 18px; }

.inspector {
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  border-left: 1px solid var(--border);
  background: var(--surface);
}

.panel {
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--surface-2);
}

.panel[hidden] { display: none !important; }

.panel-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.panel-title h2 { margin: 0; font-size: 13px; letter-spacing: .04em; }
.panel-title span { color: var(--muted); font-size: 11px; }

.icon-button { width: 32px; height: 32px; min-height: 32px; padding: 0; border-color: var(--border); background: var(--surface-3); }

.animation-preview-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 136px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 4px;
  background-color: rgba(215, 220, 226, .94);
  background-image:
    linear-gradient(45deg, rgba(142, 153, 166, .58) 25%, transparent 25%, transparent 75%, rgba(142, 153, 166, .58) 75%),
    linear-gradient(45deg, rgba(142, 153, 166, .58) 25%, transparent 25%, transparent 75%, rgba(142, 153, 166, .58) 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}

#animationPreviewCanvas {
  display: block;
  max-width: calc(100% - 18px);
  max-height: 126px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.animation-preview-message {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 14px;
  color: var(--muted);
  background: rgba(13, 16, 21, .82);
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.animation-preview-message[hidden] { display: none; }

.animation-settings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-top: 10px;
}

.animation-settings label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 10px;
}

.animation-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 9px;
  color: var(--muted);
  font-size: 10px;
}

.animation-meta output { color: var(--text); font-variant-numeric: tabular-nums; }
.animation-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-top: 10px; }
.animation-actions .button { min-width: 0; padding: 0 5px; font-size: 10px; }
.animation-actions #autoAnimation[aria-pressed="false"] { color: #cdd5df; border-color: var(--border); background: transparent; font-weight: 500; }

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

.color-row { display: grid; grid-template-columns: 54px 1fr; align-items: center; gap: 12px; }
input[type="color"] { width: 54px; height: 48px; padding: 3px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-3); cursor: pointer; }
.alpha-control { min-width: 0; }
.alpha-control label, .range-label { display: flex; justify-content: space-between; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.alpha-control output, .range-label output { color: var(--text); font-variant-numeric: tabular-nums; }
.range-label { margin-top: 14px; }
.panel > input[type="range"] { margin-bottom: 12px; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }

.statusbar {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) auto minmax(90px, 1fr);
  align-items: center;
  gap: 14px;
  padding: 0 14px 0 96px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: #11161d;
  font-size: 11px;
}

#statusText { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#pointerPosition { display: inline-flex; align-items: center; justify-content: flex-end; gap: 24px; color: #bec8d4; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
#selectionSizeReadout { color: var(--accent-2); }

.bottom-canvas-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 460px;
}

.bottom-canvas-controls strong { color: #cdd5df; font-size: 11px; }
.bottom-canvas-controls output { color: var(--accent-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bottom-canvas-controls #canvasSize { min-width: 78px; color: #cdd5df; }
.bottom-canvas-controls #zoomRange { width: 142px; }
.bottom-canvas-controls .button { min-height: 30px; height: 30px; }

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  box-shadow: 0 28px 90px rgba(0, 0, 0, .65);
}

.confirm-dialog::backdrop { background: rgba(5, 8, 12, .72); backdrop-filter: blur(3px); }
.confirm-dialog form { padding: 22px; }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 17px; }
.confirm-dialog p { margin: 0; color: var(--muted); line-height: 1.65; }
.confirm-dialog strong { color: var(--text); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

:root[data-theme="light"] .topbar { background: rgba(255, 255, 255, .98); box-shadow: 0 4px 20px rgba(15, 23, 42, .08); }
:root[data-theme="light"] .topbar-label,
:root[data-theme="light"] .button.ghost,
:root[data-theme="light"] .animation-actions #autoAnimation[aria-pressed="false"],
:root[data-theme="light"] .bottom-canvas-controls strong,
:root[data-theme="light"] .bottom-canvas-controls #canvasSize { color: var(--muted); }
:root[data-theme="light"] .button.primary { color: #ffffff; }
:root[data-theme="light"] .tool.active { color:var(--accent); border-color:var(--border); background:var(--surface-3); }
:root[data-theme="light"] .button.secondary:hover { border-color: #94a3b8; background: #e2e8f0; }
:root[data-theme="light"] .workspace { background-color: #e8edf4; background-image: linear-gradient(rgba(15,23,42,.035) 1px,transparent 1px),linear-gradient(90deg,rgba(15,23,42,.035) 1px,transparent 1px); }
:root[data-theme="light"] .workspace.drag-over::after { background: rgba(244,247,251,.9); }
:root[data-theme="light"] .animation-preview-message { background: rgba(248,250,252,.88); }
:root[data-theme="light"] .statusbar { background: #ffffff; }
:root[data-theme="light"] #pointerPosition { color: var(--muted); }
:root[data-theme="light"] .confirm-dialog::backdrop { background: rgba(15, 23, 42, .42); }

@media (max-width: 900px) {
  body { grid-template-rows: auto minmax(0, 1fr) 46px; }
  .topbar { grid-template-columns: minmax(380px, 1fr) auto; padding: 8px 12px; }
  .canvas-size-editor { grid-column: 1; grid-row: 1; justify-content:flex-start; }
  .top-actions { grid-column: 2; grid-row: 1; }
}

@media (max-width: 700px) {
  .topbar { grid-template-columns:1fr; }
  .top-actions { grid-column:1; grid-row:1; }
  .canvas-size-editor { grid-column:1; grid-row:2; justify-content:center; }
  .app-shell { grid-template-columns: 70px minmax(0, 1fr); }
  .inspector { position: fixed; right: 0; top: 120px; bottom: 46px; width: 276px; z-index: 8; transform: translateX(calc(100% - 12px)); transition: transform .2s ease; box-shadow: var(--shadow); }
  .inspector:hover, .inspector:focus-within { transform: translateX(0); }
  .workspace.drag-over::after { inset: 132px 24px 60px 84px; }
}

@media (max-width: 620px) {
  .brand span:not(.brand-mark) { display: none; }
  .top-actions .button { padding: 0 9px; font-size: 12px; }
  .app-shell { grid-template-columns: 58px minmax(0, 1fr); }
  .toolbox { padding-inline: 5px; }
  .tool { min-height: 58px; }
  .tool kbd { display: none; }
  .canvas-wrap { margin: 30px; }
  .statusbar { grid-template-columns: 1fr auto; padding-left: 66px; }
  .statusbar #statusText { display: none; }
  .bottom-canvas-controls { grid-column: 1; min-width: 0; justify-content: flex-start; }
  .bottom-canvas-controls strong { display: none; }
  .bottom-canvas-controls #zoomRange { width: 80px; }
  #pointerPosition { grid-column: 2; gap: 14px; }
}
