:root {
  --paper: #f3efe4;
  --paper-2: #e9e4d7;
  --panel: #fffdf6;
  --ink: #1d2523;
  --muted: #68706b;
  --line: #b8b5aa;
  --red: #ef5b3f;
  --red-dark: #b83d2b;
  --yellow: #f5cc58;
  --teal: #269889;
  --blue: #4f92c2;
  --shadow: #1d2523;
  --display: "Cascadia Mono", "Microsoft YaHei", "Noto Sans CJK SC", monospace;
  --body: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  color-scheme: light;
  background: var(--paper);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(29, 37, 35, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 37, 35, 0.035) 1px, transparent 1px);
  background-size: 18px 18px;
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
[role="button"]:focus-visible,
input:focus-visible + span {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

select:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

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

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 100;
  padding: 10px 14px;
  color: #fff;
  background: var(--ink);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

.topbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 24px;
  background: var(--panel);
  border-bottom: 3px solid var(--ink);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  font-family: var(--display);
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 6px);
  grid-template-rows: repeat(3, 6px);
  gap: 2px;
  width: 28px;
  height: 28px;
  margin-right: 11px;
  padding: 2px;
  background: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--yellow);
}

.brand-mark i {
  display: block;
  background: var(--paper);
}

.brand-mark i:nth-child(2),
.brand-mark i:nth-child(4),
.brand-mark i:nth-child(6),
.brand-mark i:nth-child(8) {
  background: var(--red);
}

.brand-mark i:nth-child(5) {
  background: var(--yellow);
}

.brand-word {
  overflow: hidden;
  font-size: 19px;
  font-weight: 800;
  white-space: nowrap;
}

.brand-version {
  margin-left: 12px;
  padding: 3px 6px;
  color: var(--panel);
  background: var(--ink);
  font-size: 10px;
  font-weight: 800;
}

.server-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--display);
  font-size: 12px;
  font-weight: 700;
}

.state-light {
  width: 9px;
  height: 9px;
  background: var(--yellow);
  border: 2px solid var(--ink);
}

.server-state.ready .state-light {
  background: var(--teal);
  animation: status-pulse 2.2s steps(2, end) infinite;
}

.server-state.failed .state-light {
  background: var(--red);
}

@keyframes status-pulse {
  50% { opacity: 0.5; }
}

.workspace {
  display: grid;
  grid-template-columns: 390px minmax(0, 1fr);
  height: calc(100vh - 64px);
  min-height: 640px;
}

.controls {
  overflow-y: auto;
  padding: 26px 24px 30px;
  background: rgba(255, 253, 246, 0.96);
  border-right: 3px solid var(--ink);
  scrollbar-width: thin;
  scrollbar-color: var(--ink) var(--paper-2);
}

.control-heading {
  margin-bottom: 22px;
}

.pixel-kicker {
  margin: 0 0 4px;
  color: var(--red-dark);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 800;
}

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

h1 {
  margin-bottom: 0;
  font-family: var(--display);
  font-size: 28px;
  line-height: 1.25;
}

.control-section {
  padding: 20px 0 22px;
  border-top: 2px solid var(--ink);
}

.section-title {
  display: flex;
  align-items: center;
  min-height: 28px;
  margin-bottom: 14px;
}

.section-number {
  min-width: 31px;
  margin-right: 10px;
  color: var(--red-dark);
  font-family: var(--display);
  font-size: 12px;
  font-weight: 800;
}

.section-title h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 16px;
}

.text-button {
  margin-left: auto;
  padding: 5px 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 1px solid currentColor;
  cursor: pointer;
  font-size: 12px;
}

.text-button:hover {
  color: var(--red-dark);
}

.text-button:disabled {
  color: var(--line);
  border-bottom-color: transparent;
  cursor: not-allowed;
}

.dropzone {
  display: grid;
  place-items: center;
  min-height: 176px;
  padding: 24px;
  text-align: center;
  background-color: var(--paper);
  background-image:
    linear-gradient(45deg, rgba(29, 37, 35, 0.04) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(29, 37, 35, 0.04) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(29, 37, 35, 0.04) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(29, 37, 35, 0.04) 75%);
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
  background-size: 18px 18px;
  border: 2px dashed var(--ink);
  border-radius: 3px;
  box-shadow: 4px 4px 0 var(--yellow);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.dropzone:hover,
.dropzone.dragging {
  background-color: #fff8d8;
  box-shadow: 6px 6px 0 var(--red);
  transform: translate(-2px, -2px);
}

.dropzone > * {
  pointer-events: none;
}

.upload-chip {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin-bottom: 8px;
  color: var(--panel);
  background: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--teal);
}

.upload-chip svg {
  width: 24px;
  height: 24px;
  stroke-width: 2.5;
}

.dropzone strong {
  margin-bottom: 3px;
  font-family: var(--display);
  font-size: 17px;
}

.dropzone span,
.dropzone small {
  color: var(--muted);
  font-size: 12px;
}

.dropzone small {
  margin-top: 4px;
  font-family: var(--display);
}

.file-preview {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) 36px 36px;
  align-items: center;
  gap: 12px;
  min-height: 78px;
  padding: 8px;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 var(--yellow);
}

.file-thumb {
  width: 62px;
  height: 62px;
  overflow: hidden;
  background: var(--paper-2);
  border: 2px solid var(--ink);
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-meta {
  min-width: 0;
}

.file-meta strong,
.file-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta strong {
  margin-bottom: 5px;
  font-size: 13px;
}

.file-meta span {
  color: var(--muted);
  font-family: var(--display);
  font-size: 11px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--ink);
  cursor: pointer;
}

.icon-button:hover {
  color: #fff;
  background: var(--red);
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.ratio-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 12px;
  padding: 5px;
  background: var(--paper-2);
  border: 2px solid var(--ink);
}

.ratio-option {
  min-width: 0;
  min-height: 53px;
  padding: 6px 4px;
  color: var(--muted);
  background: var(--panel);
  border: 2px solid transparent;
  cursor: pointer;
  text-align: center;
}

.ratio-option:hover {
  color: var(--ink);
  border-color: var(--line);
}

.ratio-option.active {
  color: var(--panel);
  background: var(--ink);
  border-color: var(--ink);
  box-shadow: inset 0 -4px 0 var(--teal);
}

.ratio-option strong,
.ratio-option span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ratio-option strong {
  font-family: var(--display);
  font-size: 13px;
}

.ratio-option span {
  margin-top: 3px;
  font-size: 9px;
}

.custom-size-controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: end;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: #fff8d8;
  border: 2px solid var(--ink);
}

.custom-size-controls label {
  color: var(--muted);
  font-size: 10px;
}

.custom-size-controls input {
  display: block;
  width: 100%;
  height: 36px;
  margin-top: 4px;
  padding: 0 8px;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid var(--ink);
  font-family: var(--display);
  font-size: 14px;
  font-weight: 800;
}

.custom-size-controls > span {
  padding-bottom: 9px;
  font-family: var(--display);
  font-weight: 800;
}

.apply-size-button {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 9px;
  color: var(--panel);
  background: var(--teal);
  border: 2px solid var(--ink);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.apply-size-button:hover {
  background: var(--red);
}

.apply-size-button svg {
  width: 15px;
  height: 15px;
  margin-right: 4px;
}

.size-subhead {
  display: flex;
  align-items: center;
  min-height: 25px;
  margin-bottom: 7px;
  color: var(--muted);
  font-family: var(--display);
  font-size: 10px;
}

.size-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.size-empty {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 76px;
  padding: 12px;
  color: var(--muted);
  background: var(--paper);
  border: 2px dashed var(--line);
  text-align: center;
  font-size: 11px;
}

.size-option {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  min-height: 76px;
  padding: 11px 10px;
  background: var(--paper);
  border: 2px solid var(--line);
  cursor: pointer;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.size-option:hover {
  border-color: var(--ink);
}

.size-option:has(input:checked) {
  background: #fff8d8;
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--teal);
  transform: translate(-1px, -1px);
}

.size-option input {
  position: absolute;
  opacity: 0;
}

.size-check {
  display: grid;
  grid-row: 1 / 3;
  place-items: center;
  align-self: start;
  width: 22px;
  height: 22px;
  color: transparent;
  background: var(--panel);
  border: 2px solid var(--ink);
}

.size-option input:checked + .size-check {
  color: var(--panel);
  background: var(--red);
}

.size-check svg {
  width: 15px;
  height: 15px;
  stroke-width: 3;
}

.size-main {
  align-self: center;
  font-family: var(--display);
  font-size: 16px;
  font-weight: 800;
}

.size-note,
.size-board {
  align-self: end;
  color: var(--muted);
  font-size: 10px;
}

.size-board {
  position: absolute;
  right: 9px;
  bottom: 9px;
  font-family: var(--display);
}

.compact-section {
  padding-bottom: 18px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 61px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.setting-row > div {
  min-width: 0;
}

.setting-row strong {
  display: block;
  font-size: 13px;
}

.setting-row p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.palette-setting {
  min-height: 72px;
}

.palette-select {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(78px, 1fr) 16px;
  align-items: center;
  min-width: 190px;
  height: 42px;
  overflow: hidden;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--yellow);
}

.palette-brand {
  align-self: stretch;
  display: flex;
  align-items: center;
  padding: 0 9px;
  color: #fff;
  background: var(--ink);
  font-family: var(--display);
  font-size: 10px;
  font-weight: 800;
}

.palette-select select {
  width: 100%;
  height: 100%;
  padding: 0 3px 0 10px;
  color: var(--ink);
  appearance: none;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 800;
}

.palette-select select:focus-visible {
  outline-offset: -3px;
}

.palette-select svg {
  width: 14px;
  height: 14px;
  pointer-events: none;
}

.switch {
  position: relative;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch-track {
  display: block;
  width: 48px;
  height: 26px;
  padding: 3px;
  background: var(--line);
  border: 2px solid var(--ink);
}

.switch-track span {
  display: block;
  width: 16px;
  height: 16px;
  background: var(--panel);
  border: 2px solid var(--ink);
  transition: transform 140ms steps(2, end);
}

.switch input:checked + .switch-track {
  background: var(--teal);
}

.switch input:checked + .switch-track span {
  transform: translateX(20px);
}

.action-bar {
  padding-top: 4px;
}

.primary-button,
.download-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  color: #fff;
  background: var(--red);
  border: 2px solid var(--ink);
  border-radius: 3px;
  box-shadow: 5px 5px 0 var(--ink);
  cursor: pointer;
  font-family: var(--display);
  font-weight: 800;
  text-decoration: none;
  transition: transform 100ms ease, box-shadow 100ms ease, background 100ms ease;
}

.primary-button {
  width: 100%;
  padding: 0 14px;
  font-size: 15px;
}

.primary-button svg,
.download-button svg {
  width: 20px;
  height: 20px;
  margin-right: 9px;
}

.primary-button kbd {
  margin-left: auto;
  padding: 3px 6px;
  color: var(--ink);
  background: var(--yellow);
  border: 1px solid var(--ink);
  font-family: var(--display);
  font-size: 10px;
}

.primary-button:hover:not(:disabled),
.download-button:hover {
  background: var(--red-dark);
  box-shadow: 3px 3px 0 var(--ink);
  transform: translate(2px, 2px);
}

.primary-button:disabled {
  color: #727773;
  background: #c9c8c1;
  box-shadow: 3px 3px 0 #777b78;
  cursor: not-allowed;
}

.action-bar p {
  margin: 11px 0 0;
  color: var(--muted);
  text-align: center;
  font-family: var(--display);
  font-size: 11px;
}

.workbench {
  min-width: 0;
  overflow-y: auto;
  padding: 26px 28px 42px;
}

.workbench-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.workbench-bar h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 24px;
}

.canvas-status {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  background: var(--panel);
  border: 2px solid var(--ink);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 800;
}

.canvas-status svg {
  width: 16px;
  height: 16px;
}

.canvas-status.active {
  color: #fff;
  background: var(--teal);
}

.canvas-stage {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  background-color: var(--panel);
  background-image:
    linear-gradient(rgba(29, 37, 35, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(29, 37, 35, 0.055) 1px, transparent 1px);
  background-size: 22px 22px;
  border: 3px solid var(--ink);
  box-shadow: 7px 7px 0 rgba(29, 37, 35, 0.2);
}

.canvas-stage::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 18px;
  height: 18px;
  background: var(--yellow);
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

.canvas-stage:has(.result-view:not([hidden])) {
  min-height: 0;
}

.empty-state,
.processing-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 514px;
  padding: 40px;
}

.demo-board {
  display: grid;
  grid-template-columns: repeat(14, 12px);
  grid-auto-rows: 12px;
  gap: 3px;
  margin-bottom: 26px;
  padding: 13px;
  background: rgba(255, 253, 246, 0.92);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 var(--teal);
  transform: rotate(-2deg);
}

.demo-pixel {
  width: 12px;
  height: 12px;
  background: var(--paper-2);
  border: 1px solid rgba(29, 37, 35, 0.22);
}

.demo-pixel.hair { background: #2f2b29; }
.demo-pixel.skin { background: #efb6a4; }
.demo-pixel.shirt { background: #dce0e2; }
.demo-pixel.eye { background: #1d2523; }
.demo-pixel.mouth { background: #c64b5d; }
.demo-pixel.accent { background: var(--yellow); }

.empty-copy {
  text-align: center;
}

.empty-copy strong {
  display: inline-block;
  font-family: var(--display);
  font-size: 16px;
}

.empty-copy p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.cursor-block {
  display: inline-block;
  width: 8px;
  height: 15px;
  margin-right: 7px;
  vertical-align: -2px;
  background: var(--red);
  animation: cursor-blink 1s steps(2, end) infinite;
}

@keyframes cursor-blink {
  50% { opacity: 0; }
}

.processing-board {
  position: relative;
  width: 146px;
  height: 146px;
  margin-bottom: 28px;
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 var(--yellow);
}

.processing-board span {
  position: absolute;
  width: 18px;
  height: 18px;
  background: var(--red);
  border: 2px solid var(--ink);
  animation: bead-scan 1.5s steps(4, end) infinite;
}

.processing-board span:nth-child(1) { top: 18px; left: 18px; }
.processing-board span:nth-child(2) { top: 18px; right: 18px; animation-delay: 120ms; background: var(--yellow); }
.processing-board span:nth-child(3) { top: 62px; left: 62px; animation-delay: 240ms; background: var(--teal); }
.processing-board span:nth-child(4) { bottom: 18px; left: 18px; animation-delay: 360ms; background: var(--blue); }
.processing-board span:nth-child(5) { right: 18px; bottom: 18px; animation-delay: 480ms; }

@keyframes bead-scan {
  50% { transform: scale(1.45); }
}

.processing-label {
  margin: 0 0 12px;
  color: var(--muted);
  font-family: var(--display);
  font-size: 13px;
}

.progress-track {
  width: min(360px, 80%);
  height: 18px;
  padding: 3px;
  background: var(--paper-2);
  border: 2px solid var(--ink);
}

.progress-track span {
  display: block;
  width: 0;
  height: 8px;
  background: var(--teal);
  transition: width 400ms steps(8, end);
}

.processing-state > strong {
  margin-top: 10px;
  font-family: var(--display);
  font-size: 20px;
}

.result-view {
  padding: 24px;
}

.comparison-frame {
  min-height: 300px;
  overflow: hidden;
  background: var(--paper-2);
  border: 2px solid var(--ink);
}

.comparison-frame img {
  display: block;
  width: 100%;
  height: auto;
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding-top: 18px;
}

.result-actions > div {
  min-width: 0;
}

.result-actions strong,
.result-actions span {
  display: block;
}

.result-actions strong {
  margin-bottom: 4px;
  font-family: var(--display);
  font-size: 17px;
}

.result-actions span {
  color: var(--muted);
  font-size: 11px;
}

.download-button {
  min-width: 170px;
  min-height: 46px;
  padding: 0 15px;
  white-space: nowrap;
  font-size: 13px;
}

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

.pattern-item {
  display: grid;
  grid-template-columns: 68px 1fr auto;
  align-items: center;
  gap: 13px;
  min-height: 92px;
  padding: 10px;
  background: var(--panel);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--paper-2);
}

.pattern-thumb {
  width: 68px;
  height: 68px;
  object-fit: contain;
  background-color: #f5f3ed;
  background-image:
    linear-gradient(45deg, #e5e3dc 25%, transparent 25%),
    linear-gradient(-45deg, #e5e3dc 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e3dc 75%),
    linear-gradient(-45deg, transparent 75%, #e5e3dc 75%);
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
  background-size: 12px 12px;
  border: 1px solid var(--line);
  image-rendering: pixelated;
}

.pattern-meta strong,
.pattern-meta span {
  display: block;
}

.pattern-meta strong {
  margin-bottom: 4px;
  font-family: var(--display);
  font-size: 16px;
}

.pattern-meta span {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.55;
}

.chart-link {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  color: var(--ink);
  background: var(--yellow);
  border: 2px solid var(--ink);
  text-decoration: none;
}

.chart-link:hover {
  color: #fff;
  background: var(--teal);
}

.chart-link svg {
  width: 19px;
  height: 19px;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 50;
  display: flex;
  align-items: center;
  max-width: min(420px, calc(100vw - 32px));
  min-height: 52px;
  padding: 12px 16px;
  color: #fff;
  background: var(--red-dark);
  border: 2px solid var(--ink);
  box-shadow: 5px 5px 0 var(--ink);
  font-size: 13px;
}

.toast svg {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin-right: 9px;
}

.crop-dialog {
  width: min(1040px, calc(100vw - 36px));
  max-width: none;
  max-height: calc(100dvh - 36px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--panel);
  border: 3px solid var(--ink);
  border-radius: 3px;
  box-shadow: 9px 9px 0 rgba(29, 37, 35, 0.45);
}

.crop-dialog::backdrop {
  background: rgba(22, 28, 27, 0.72);
}

.crop-shell {
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  max-height: calc(100dvh - 42px);
}

.crop-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 74px;
  padding: 12px 16px 12px 20px;
  background: var(--panel);
  border-bottom: 3px solid var(--ink);
}

.crop-header > div:first-child {
  min-width: 0;
  margin-right: auto;
}

.crop-header h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 21px;
}

.ratio-badge {
  padding: 5px 8px;
  color: var(--ink);
  background: var(--yellow);
  border: 2px solid var(--ink);
  font-family: var(--display);
  font-size: 12px;
  font-weight: 800;
}

.crop-stage {
  min-height: 0;
  height: min(58dvh, 640px);
  padding: 14px;
  overflow: hidden;
  background-color: #262b2a;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, 0.035) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.crop-stage > img {
  display: block;
  max-width: 100%;
}

.cropper-container {
  width: 100% !important;
  height: 100% !important;
  font-family: var(--body);
}

.cropper-view-box,
.cropper-face {
  border-radius: 0;
}

.cropper-view-box {
  outline: 3px solid var(--yellow);
  outline-color: var(--yellow);
}

.cropper-line,
.cropper-point {
  background-color: var(--red);
}

.crop-footer {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  min-height: 86px;
  padding: 13px 16px 14px 20px;
  background: var(--panel);
  border-top: 3px solid var(--ink);
}

.crop-status {
  min-width: 0;
  color: var(--muted);
  font-family: var(--display);
  font-size: 11px;
  line-height: 1.5;
}

.crop-controls,
.crop-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.tool-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  cursor: pointer;
}

.tool-button:hover {
  color: #fff;
  background: var(--teal);
}

.tool-button svg {
  width: 18px;
  height: 18px;
}

.secondary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 13px;
  color: var(--ink);
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 3px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
  font-family: var(--display);
  font-size: 12px;
  font-weight: 800;
}

.secondary-button:hover:not(:disabled) {
  color: #fff;
  background: var(--teal);
  transform: translate(1px, 1px);
  box-shadow: 2px 2px 0 var(--ink);
}

.secondary-button:disabled {
  color: #7d817e;
  background: #cfcdc5;
  box-shadow: none;
  cursor: not-allowed;
}

.secondary-button svg {
  width: 18px;
  height: 18px;
  margin-right: 7px;
}

.apply-crop-button {
  width: auto;
  min-width: 128px;
  min-height: 44px;
  padding: 0 13px;
  font-size: 12px;
}

.apply-crop-button svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 1050px) {
  .workspace {
    grid-template-columns: 350px minmax(0, 1fr);
  }

  .controls {
    padding-right: 19px;
    padding-left: 19px;
  }

  .workbench {
    padding-right: 20px;
    padding-left: 20px;
  }

  .pattern-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar {
    position: sticky;
    top: 0;
    height: 58px;
    padding: 0 15px;
  }

  .brand-version {
    display: none;
  }

  .brand-word {
    font-size: 16px;
  }

  .server-state span:last-child {
    display: none;
  }

  .workspace {
    display: block;
    height: auto;
    min-height: 0;
  }

  .controls {
    overflow: visible;
    padding: 22px 16px 25px;
    border-right: 0;
    border-bottom: 3px solid var(--ink);
  }

  .workbench {
    overflow: visible;
    padding: 22px 14px 40px;
  }

  .canvas-stage {
    min-height: 420px;
    box-shadow: 5px 5px 0 rgba(29, 37, 35, 0.2);
  }

  .empty-state,
  .processing-state {
    min-height: 414px;
    padding: 28px 16px;
  }

  .demo-board {
    grid-template-columns: repeat(14, 9px);
    grid-auto-rows: 9px;
    gap: 2px;
  }

  .demo-pixel {
    width: 9px;
    height: 9px;
  }

  .result-view {
    padding: 14px;
  }

  .comparison-frame {
    min-height: 0;
  }

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

  .download-button {
    width: 100%;
  }

  .pattern-list {
    grid-template-columns: 1fr;
  }

  .toast {
    right: 16px;
    bottom: 16px;
    left: 16px;
  }

  .crop-dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .crop-shell {
    max-height: calc(100dvh - 22px);
    grid-template-rows: auto minmax(240px, 1fr) auto;
  }

  .crop-header {
    min-height: 64px;
    padding: 9px 10px 9px 13px;
  }

  .crop-header h2 {
    font-size: 18px;
  }

  .crop-stage {
    height: 48dvh;
    padding: 8px;
  }

  .crop-footer {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 11px 12px 14px;
  }

  .crop-status {
    min-height: 17px;
    text-align: center;
  }

  .crop-controls,
  .crop-actions {
    justify-content: center;
  }

  .crop-actions > button {
    flex: 1;
  }
}

@media (max-width: 390px) {
  .palette-setting {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .palette-select {
    width: 100%;
  }

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

  .size-grid {
    grid-template-columns: 1fr;
  }

  .size-option {
    min-height: 65px;
  }

  h1 {
    font-size: 25px;
  }

  .workbench-bar h2 {
    font-size: 21px;
  }

  .canvas-status {
    padding: 6px;
  }

  .pattern-item {
    grid-template-columns: 58px 1fr 38px;
    gap: 9px;
  }

  .pattern-thumb {
    width: 58px;
    height: 58px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
