@font-face {
  font-family: "Jersey 10";
  src: url("vendor/fonts/jersey-10/Jersey10-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-2: #f6f8fa;
  --ink: #1f2328;
  --text-secondary: #4d5761;
  --on-ink: #ffffff;
  --on-accent: #ffffff;
  --ink-hover: #0550ae;
  --muted: #6e7781;
  --line: #eaeef2;
  --accent: #0969da;
  --accent-dark: #0550ae;
  --teal: #0969da;
  --shadow: 0 8px 30px rgba(31, 35, 40, .12);
  --stage: #f6f8fa;
  --bar: rgba(255, 255, 255, .82);
  --bar-line: #eaeef2;
  --input: #ffffff;
  --hover: #f6f8fa;
  --checker-a: #eaeef2;
  --checker-b: #ffffff;
  --dot-grid: #d0d7de;
  --teal-soft: #ddf4ff;
  --teal-soft-hover: #b6e3ff;
  --teal-line: #54aeff;
  --accent-soft: #ddf4ff;
  --accent-soft-hover: #b6e3ff;
  --palette-line: #eaeef2;
  --control-off: #d0d7de;
  --control-knob: #ffffff;
  --grid-line: rgba(31, 35, 40, .26);
  --grid-major: rgba(31, 35, 40, .46);
  --control-gap: 14px;
  --text-xs: 12px;
  --text-sm: 14px;
  --text-md: 16px;
  --text-lg: 18px;
  --text-brand: 22px;
  --weight-regular: 400;
  --weight-medium: 600;
  --weight-bold: 700;
  --line-height-tight: 1.2;
  --line-height-compact: 1.4;
  --radius-ui: 5px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #151819;
  --surface: #151819;
  --surface-2: #202428;
  --ink: #e6edf3;
  --text-secondary: #c2c9d0;
  --on-ink: #151819;
  --on-accent: #0d1113;
  --ink-hover: #39d353;
  --muted: #8b949e;
  --line: #272c31;
  --accent: #26a641;
  --accent-dark: #39d353;
  --teal: #26a641;
  --shadow: 0 10px 34px rgba(0, 0, 0, .34);
  --stage: #151819;
  --bar: rgba(21, 24, 25, .84);
  --bar-line: #272c31;
  --input: #202428;
  --hover: #202428;
  --checker-a: #202428;
  --checker-b: #272c31;
  --dot-grid: #30363d;
  --teal-soft: #0e4429;
  --teal-soft-hover: #006d32;
  --teal-line: #26a641;
  --accent-soft: #0e4429;
  --accent-soft-hover: #006d32;
  --palette-line: #272c31;
  --control-off: #30363d;
  --control-knob: #e6edf3;
  --grid-line: rgba(230, 237, 243, .24);
  --grid-major: rgba(230, 237, 243, .44);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--text-secondary);
  background: var(--bg);
  font-family: "Noto Sans SC", "Microsoft YaHei UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: var(--text-sm);
  line-height: var(--line-height-compact);
  letter-spacing: 0;
}

button, input { font: inherit; }
button { color: inherit; }
input[type="number"] {
  appearance: auto;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  opacity: 1;
  cursor: ns-resize;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.lucide {
  display: block;
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
  stroke-width: 1.75;
}
.btn > .lucide { width: 15px; height: 15px; }

.app-shell { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: 58px;
  flex: 0 0 58px;
  display: grid;
  grid-template-columns: 250px 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 0 16px 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--bar);
  -webkit-backdrop-filter: saturate(150%) blur(12px);
  backdrop-filter: saturate(150%) blur(12px);
  z-index: 10;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: "Jersey 10", "Cascadia Mono", Consolas, monospace;
  font-weight: var(--weight-regular);
  font-size: var(--text-brand);
  line-height: 1;
}

.brand-mark {
  width: 25px;
  height: 25px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 2px;
  transform: rotate(45deg) scale(.82);
}
.brand-mark i { display: block; background: var(--ink); }
.brand-mark i:nth-child(2), .brand-mark i:nth-child(3) { background: var(--accent); }

.document-title { min-width: 0; text-align: center; }
.document-title input {
  width: min(260px, 100%);
  padding: 2px 6px;
  border: 0;
  border-radius: 3px;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  text-align: center;
}
.document-title input[readonly] { cursor: default; }
.document-title input:not([readonly]) { background: var(--input); box-shadow: 0 0 0 1px var(--line); }
.document-title span { display: block; margin-top: 1px; color: var(--muted); font-size: var(--text-xs); }

.top-actions { display: flex; gap: 8px; }
.language-select {
  height: 34px;
  padding: 0 24px 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-ui);
  outline: 0;
  background: var(--surface);
  color: var(--ink);
  font-size: var(--text-xs);
  cursor: pointer;
}
.language-select:hover, .language-select:focus { border-color: var(--muted); }
.btn {
  min-height: 34px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius-ui);
  background: var(--surface);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: var(--line-height-tight);
  cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s, transform .1s;
}
.btn:hover { border-color: var(--muted); background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { border-color: var(--ink-hover); background: var(--ink-hover); }
.btn:disabled { cursor: not-allowed; opacity: .6; }

.theme-toggle {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-ui);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--muted); background: var(--surface-2); }
.theme-icon { width: 17px; height: 17px; }
.theme-sun { display: none; }
:root[data-theme="dark"] .theme-moon { display: none; }
:root[data-theme="dark"] .theme-sun { display: block; }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 52px minmax(360px, 1fr) 318px;
}

.toolrail {
  padding: 10px 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.tool, .icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-ui);
  background: transparent;
  cursor: pointer;
  line-height: 1;
  display: grid;
  place-items: center;
}
.tool .lucide { width: 18px; height: 18px; }
.icon-btn .lucide { width: 17px; height: 17px; }
.tool:hover, .icon-btn:hover { background: var(--surface-2); border-color: var(--line); }
.tool.active { background: var(--accent); color: var(--on-accent); }
.rail-separator { width: 24px; height: 1px; margin: 5px 0; background: var(--line); }
.color-tool {
  position: relative;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-ui);
  cursor: pointer;
}
.color-tool:hover { border-color: var(--line); background: var(--surface-2); }
.color-tool:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.color-tool input { position: absolute; opacity: 0; pointer-events: none; }
.color-tool span { display: block; width: 27px; height: 27px; border: 3px solid var(--surface); border-radius: var(--radius-ui); outline: 1px solid var(--muted); background: var(--accent); }
.color-tool::after { content: ""; position: absolute; right: 1px; bottom: 1px; width: 10px; height: 10px; border: 1px solid var(--muted); border-radius: 2px; background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 / 6px 6px; }

.stage-area { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--stage); }
.commandbar {
  height: 48px;
  flex: 0 0 48px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--bar-line);
  background: var(--bar);
}
.command-group { display: flex; align-items: center; gap: 4px; }
.command-group + .command-group { padding-left: 12px; border-left: 1px solid var(--line); }
.command-group label { margin-right: 4px; color: var(--muted); font-size: var(--text-xs); }
.command-group input {
  width: 54px;
  height: 28px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  text-align: center;
}
.command-group input:focus {
  border-color: var(--accent);
  outline: 0;
  box-shadow: 0 0 0 1px var(--accent);
}
.commandbar .icon-btn { width: 30px; height: 30px; }
.text-btn, .link-button {
  border: 0;
  background: transparent;
  color: var(--teal);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  line-height: var(--line-height-tight);
  cursor: pointer;
}
.text-btn { height: 28px; padding: 0 7px; color: var(--ink); }
.zoom-control { margin-left: auto; }
.zoom-control > span { width: 43px; color: var(--muted); font-size: var(--text-xs); text-align: center; }
.compare-control { flex: 0 0 auto; }
.compare-btn { display: inline-flex; align-items: center; gap: 6px; padding-inline: 8px; }
.compare-btn .lucide { width: 15px; height: 15px; }
.compare-btn.active { border-radius: 4px; background: var(--accent); color: var(--on-accent); }

.canvas-viewport {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 28px;
  background-image: radial-gradient(var(--dot-grid) 0.7px, transparent 0.7px);
  background-size: 16px 16px;
}
.canvas-wrap {
  width: min(68vh, calc(100vw - 470px));
  max-width: 680px;
  min-width: 240px;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 12px 22px rgba(0, 0, 0, .24));
  transform-origin: center;
}
.canvas-stack {
  position: relative;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
}
.canvas-stack.portrait { width: auto; height: 100%; }
#pixelCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 / 20px 20px;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}
#gridCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#compareCanvas {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.compare-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  z-index: 4;
  display: none;
  width: 24px;
  margin-left: -12px;
  cursor: ew-resize;
  touch-action: none;
}
.compare-divider::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  background: rgba(255, 255, 255, .9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .35);
}
.compare-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, .45);
  border-radius: 50%;
  background: #fff;
  color: #191b1a;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
  transform: translate(-50%, -50%);
}
.compare-handle .lucide { width: 15px; height: 15px; }
.compare-label {
  position: absolute;
  top: 10px;
  z-index: 5;
  display: none;
  padding: 4px 7px;
  border-radius: 3px;
  background: rgba(20, 22, 21, .76);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: var(--weight-bold);
  pointer-events: none;
}
.original-label { left: 10px; }
.result-label { right: 10px; }
.canvas-stack.comparing #pixelCanvas { pointer-events: none; }
.canvas-stack.comparing #gridCanvas { opacity: 0; }
.canvas-stack.comparing #compareCanvas,
.canvas-stack.comparing .compare-divider,
.canvas-stack.comparing .compare-label { display: block; }
.statusbar {
  height: 30px;
  flex: 0 0 30px;
  padding: 0 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--bar-line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-xs);
}
.statusbar > div { min-width: 0; white-space: nowrap; }
.statusbar > div:last-child { overflow: hidden; text-overflow: ellipsis; text-align: right; }
.status-dot { display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; background: var(--teal); }

.inspector { min-width: 0; min-height: 0; overflow: hidden; border-left: 1px solid var(--line); background: var(--surface); }
.tabs { height: 48px; display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.tab { position: relative; border: 0; background: transparent; color: var(--muted); font-size: var(--text-sm); font-weight: var(--weight-medium); cursor: pointer; }
.tab.active { color: var(--ink); }
.tab.active::after { content: ""; position: absolute; left: 22px; right: 22px; bottom: -1px; height: 2px; background: var(--accent); }
.panel { display: none; height: calc(100% - 48px); overflow-y: auto; }
.panel.active { display: block; }
.inspector-section {
  padding: 18px 17px;
  display: flex;
  flex-direction: column;
  gap: var(--control-gap);
  border-bottom: 1px solid var(--line);
}
.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 0; }
.section-heading h2 { margin: 0; color: var(--ink); font-size: var(--text-sm); font-weight: var(--weight-bold); line-height: var(--line-height-tight); }
.tag { padding: 3px 6px; border-radius: 3px; background: var(--teal-soft); color: var(--teal); font-size: var(--text-xs); font-weight: var(--weight-bold); line-height: var(--line-height-tight); }
.tag.neutral { background: var(--surface-2); color: var(--muted); }

.dropzone {
  width: 100%;
  min-height: 105px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px dashed var(--muted);
  border-radius: var(--radius-ui);
  background: var(--surface-2);
  cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: var(--accent-soft-hover); }
.drop-icon { width: 23px; height: 23px; color: var(--accent); }
.dropzone strong { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.dropzone small { color: var(--muted); font-size: var(--text-xs); }

.detect-grid-btn {
  width: 100%;
  min-height: 54px;
  padding: 8px 9px;
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--teal-line);
  border-radius: var(--radius-ui);
  background: var(--teal-soft);
  text-align: left;
  cursor: pointer;
  transition: background-color .15s, border-color .15s;
}
.detect-grid-btn:hover { border-color: var(--teal); background: var(--teal-soft-hover); }
.detect-grid-btn:disabled { cursor: wait; opacity: .7; }
.detect-grid-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--teal);
  color: white;
}
.detect-grid-icon .lucide { width: 15px; height: 15px; }
.detect-grid-btn > span:nth-child(2) { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.detect-grid-btn b { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.detect-grid-btn small { overflow: hidden; color: var(--muted); font-size: var(--text-xs); text-overflow: ellipsis; white-space: nowrap; }
.detect-grid-btn em { color: var(--teal); font-size: var(--text-xs); font-style: normal; font-weight: var(--weight-bold); }
.detect-grid-btn.analyzing .detect-grid-icon { animation: detect-pulse .75s ease-in-out infinite alternate; }
@keyframes detect-pulse { to { opacity: .45; transform: scale(.88); } }

.field-row, .toggle-row, .range-row {
  min-height: 34px;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 12px;
}
.number-field { height: 30px; display: flex; align-items: center; border: 1px solid var(--line); border-radius: 4px; background: var(--input); }
.number-field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.number-field input { width: 58px; height: 100%; padding: 0 0 0 6px; border: 0; outline: 0; background: transparent; text-align: right; }
.number-field em { padding: 0 7px 0 4px; color: var(--muted); font-size: var(--text-xs); font-style: normal; }
.range-row b, .toggle-row b { font-weight: var(--weight-regular); }
.range-row output { color: var(--muted); font-size: var(--text-xs); }
.control-label { display: flex; align-items: center; align-self: stretch; }
.range-control {
  width: 150px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: center;
  gap: 7px;
}
.range-control output { text-align: right; font-variant-numeric: tabular-nums; }
input[type="range"] { width: 100%; height: 3px; margin: 0; accent-color: var(--accent); }
.range-row.compact { margin: 0; }
.toggle-row { cursor: pointer; }
.toggle-row > span { display: flex; min-width: 0; flex-direction: column; gap: 3px; }
.toggle-row small { color: var(--muted); font-size: var(--text-xs); }
.toggle-row input { display: none; }
.toggle-row i { position: relative; width: 32px; height: 18px; flex: 0 0 32px; border-radius: 9px; background: var(--control-off); transition: background .15s; }
.toggle-row i::after { content: ""; position: absolute; width: 14px; height: 14px; top: 2px; left: 2px; border-radius: 50%; background: var(--control-knob); transition: transform .15s; }
.toggle-row input:checked + i { background: var(--teal); }
.toggle-row input:checked + i::after { transform: translateX(14px); }
.refine-btn { width: 100%; margin: 0; }

.palette-header { gap: 8px; }
.palette-header p { margin: 0; color: var(--muted); font-size: var(--text-xs); line-height: var(--line-height-compact); }
.palette-list { padding: 8px 17px 20px; }
.palette-item { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--palette-line); cursor: pointer; }
.palette-item.active { color: var(--accent-dark); }
.palette-swatch { width: 32px; height: 32px; border: 1px solid var(--line); }
.palette-value { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: var(--text-sm); text-transform: uppercase; }
.palette-usage { color: var(--muted); font-size: var(--text-xs); }

.bg-field input { width: 36px; height: 26px; padding: 1px; border: 1px solid var(--line); background: var(--input); }
.bg-field.disabled { opacity: .4; pointer-events: none; }
.svg-preview {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid var(--line);
  background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 / 16px 16px;
}
.svg-preview svg, .svg-preview img { display: block; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.export-meta { display: flex; justify-content: space-between; margin: 0; color: var(--muted); font-size: var(--text-xs); }
.wide { width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 42px;
  z-index: 30;
  padding: 9px 14px;
  border-radius: 5px;
  background: var(--ink);
  color: var(--on-ink);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 8px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-shell { height: auto; min-height: 100%; }
  .topbar { grid-template-columns: 1fr auto; }
  .document-title { display: none; }
  .workspace { grid-template-columns: 48px minmax(0, 1fr); grid-template-rows: minmax(520px, calc(100vh - 58px)) auto; }
  .inspector { grid-column: 1 / -1; min-height: 620px; border-top: 1px solid var(--line); border-left: 0; }
  .panel { height: auto; }
  .canvas-wrap { width: min(70vh, calc(100vw - 110px)); }
}

@media (max-width: 560px) {
  .topbar { height: 54px; grid-template-columns: 1fr auto; gap: 8px; padding: 0 10px; }
  .brand { font-size: var(--text-brand); }
  .brand-mark { width: 21px; height: 21px; }
  .top-actions .secondary { display: none; }
  .language-select { width: 44px; padding-inline: 5px; }
  .top-actions .btn { padding: 0 10px; }
  .workspace { grid-template-columns: 44px minmax(0, 1fr); grid-template-rows: 530px auto; }
  .toolrail { padding-inline: 4px; }
  .tool { width: 34px; }
  .commandbar { padding-inline: 6px; gap: 4px; overflow-x: auto; }
  .command-group + .command-group { padding-left: 5px; }
  .size-control label, .size-control .text-btn { display: none; }
  .zoom-control { margin-left: 0; }
  .compare-control { padding-left: 3px; }
  .compare-btn { padding-inline: 5px; }
  .canvas-viewport { padding: 16px 8px; }
  .canvas-wrap { width: min(calc(100vw - 70px), 430px); min-width: 0; }
  .statusbar div:nth-child(2) { display: none; }
  .statusbar { gap: 10px; }
  .statusbar > div:last-child { max-width: 44%; }
}
