:root {
  color-scheme: light;
  --bg: #fbf6f8;
  --surface: #fffdfd;
  --surface-soft: #fff8f7;
  --surface-mint: #fdf0f4;
  --ink: #342e39;
  --muted: #766e7a;
  --faint: #a79ea8;
  --line: #eee5e9;
  --line-strong: #e2d6dc;
  --mint: #c55f82;
  --mint-dark: #a9466a;
  --mint-soft: #f6dce6;
  --yellow: #f3ba72;
  --yellow-dark: #c78331;
  --danger: #d9676e;
  --danger-dark: #b84750;
  --shadow-soft: 0 10px 28px rgba(74, 44, 58, 0.08);
  --radius: 8px;
  --topbar: 64px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  min-width: 1120px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

.icon-sprite {
  display: none;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  flex: 0 0 auto;
}

.topbar {
  display: grid;
  grid-template-columns: 328px auto minmax(150px, 1fr) auto;
  align-items: center;
  height: var(--topbar);
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  height: 100%;
  padding: 0 20px;
  color: var(--ink);
  text-decoration: none;
  border-right: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 9px);
  gap: 3px;
  width: 43px;
  height: 43px;
  padding: 4px;
  border: 1px solid #e4e9e8;
  border-radius: 10px;
  background: #fbfdfd;
}

.brand-mark i {
  display: block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.12),
    inset 0 0 0 3px rgba(255, 255, 255, 0.12);
}

.brand-mark i:nth-child(1) { background: #ead5b9; }
.brand-mark i:nth-child(2) { background: #a7ddd4; }
.brand-mark i:nth-child(3) { background: #20aa9b; }
.brand-mark i:nth-child(4) { background: #704d37; }
.brand-mark i:nth-child(5) { background: #f0a034; }
.brand-mark i:nth-child(6) { background: #e97867; }
.brand-mark i:nth-child(7) { background: #eef1e7; }
.brand-mark i:nth-child(8) { background: #b9c3ca; }
.brand-mark i:nth-child(9) { background: #d54c59; }

.brand strong {
  display: inline-block;
  margin-right: 7px;
  font-size: 21px;
  font-weight: 900;
  letter-spacing: 0;
}

.brand small {
  display: inline-block;
  color: #68727b;
  font-size: 13px;
  font-weight: 750;
}

.topbar-actions,
.topbar-history,
.topbar-right,
.tool-tabs,
.view-tools {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 14px;
  padding-left: 20px;
}

.topbar-history {
  justify-self: end;
  gap: 16px;
  padding-right: 18px;
}

.topbar-right {
  justify-self: end;
  gap: 12px;
  padding-right: 18px;
}

.topbar-button,
.icon-button,
.tool-tab,
.zoom-button,
.outline-button,
.generate-button,
.download-button,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  color: var(--ink);
  background: transparent;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background-color 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.license-button.is-active {
  color: var(--mint-dark);
}

.topbar-button {
  min-height: 36px;
  padding: 0 2px;
}

.topbar-button:hover,
.icon-button:hover,
.tool-tab:hover,
.zoom-button:hover,
.toolbar-toggle:hover,
.zoom-slider-control:hover {
  color: var(--mint-dark);
}

#resetButton {
  color: #66717d;
}

#resetButton:hover {
  color: #b42318;
}

.topbar-button:disabled,
.muted-action {
  color: #8c949f;
  cursor: not-allowed;
}

.topbar-button:not(:disabled).muted-action {
  color: var(--ink);
  cursor: pointer;
}

.icon-button {
  width: 38px;
  height: 38px;
}

.app-shell {
  display: grid;
  grid-template-columns: 328px minmax(0, 1fr) 352px;
  height: calc(100vh - var(--topbar));
  background: var(--surface);
}

.side-panel {
  min-height: 0;
  overflow: auto;
  background: var(--surface);
}

.tool-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border-right: 1px solid var(--line);
}

.tool-panel-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 18px 18px 96px;
}

.tool-panel-cta {
  flex: 0 0 auto;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.summary-panel {
  padding: 0 18px 18px;
  border-left: 1px solid var(--line);
}

.step-section {
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.control-stack .step-section:last-of-type {
  margin-bottom: 12px;
}

.step-heading,
.section-heading > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.step-heading {
  margin-bottom: 12px;
}

.step-heading h1,
.step-heading h2,
.legend-section h2,
.info-section h2,
.tip-box h2 {
  margin: 0;
  font-size: 16px;
  line-height: 1.25;
  font-weight: 850;
  letter-spacing: 0;
}

.step-badge {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #eef3f4;
  color: var(--mint-dark);
  font-size: 11px;
  font-weight: 900;
  box-shadow: none;
}

.upload-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 120px;
  overflow: hidden;
  border: 1px dashed #e5a7ba;
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, rgba(197, 95, 130, 0.07) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(197, 95, 130, 0.07) 25%, transparent 25%),
    #ffffff;
  background-size: 20px 20px;
  cursor: pointer;
  transition:
    border-color 140ms ease,
    background-color 140ms ease;
}

.upload-zone.is-dragging {
  border-color: var(--mint-dark);
  background-color: #fff0f4;
}

.upload-zone:focus-visible {
  border-color: var(--mint);
  outline: 3px solid rgba(197, 95, 130, 0.18);
  outline-offset: 3px;
}

.upload-zone input {
  display: none;
}

#sourcePreview {
  width: 100%;
  height: 100%;
  max-height: 188px;
  object-fit: contain;
  image-rendering: pixelated;
}

.upload-placeholder {
  display: grid;
  justify-items: center;
  gap: 6px;
  color: var(--muted);
  text-align: center;
}

.upload-placeholder svg {
  width: 26px;
  height: 26px;
  color: var(--mint-dark);
}

.upload-placeholder strong {
  color: var(--ink);
  font-size: 15px;
}

.upload-placeholder span,
.source-meta {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.source-meta {
  min-height: 18px;
  margin: 8px 0;
}

.upload-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.upload-actions .outline-button {
  min-width: 0;
  padding: 0 8px;
}

.outline-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: #4e5661;
}

.outline-button:hover {
  background: #f8fafb;
  border-color: #c7ced8;
  color: var(--mint-dark);
}

.wide {
  width: 100%;
}

.control-stack {
  display: block;
  padding-bottom: 0;
}

.mobile-settings {
  display: contents;
}

.mobile-settings > summary {
  display: none;
}

.control-block,
.control-field,
.control-row,
.stepper-field {
  display: grid;
  gap: 8px;
  margin-bottom: 13px;
}

.preset-select {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.preset-select select {
  min-width: 0;
  min-height: 34px;
  height: 34px;
  font-size: 13px;
}

.field-title,
.control-row,
.stepper-field > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.field-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-title svg {
  width: 17px;
  height: 17px;
  color: #7d8792;
}

.dimension-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr 70px;
  align-items: center;
  gap: 8px;
}

.dimension-grid input,
.mini-button,
select,
.stepper,
.segmented label span {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
}

.dimension-grid input {
  display: grid;
  place-items: center;
  width: 100%;
  padding: 0 12px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  outline: none;
}

.dimension-grid input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(34, 184, 169, 0.14);
}

.dimension-grid input::-webkit-outer-spin-button,
.dimension-grid input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.dimension-grid input[type="number"] {
  appearance: textfield;
}

.dimension-grid > span {
  color: var(--faint);
  font-weight: 800;
}

.mini-button {
  color: #707985;
}

.mini-button.is-active {
  border-color: #e7aac0;
  background: #fff0f4;
  color: var(--mint-dark);
}

.control-field > span,
.control-row > span,
.switch-row > span,
.stepper-field > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
  outline: none;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.segmented input:checked + span {
  border-color: #e7a0ba;
  background: #fff0f4;
  color: var(--mint-dark);
  box-shadow: inset 0 0 0 1px #f8d8e3;
}

.segmented input:disabled + span {
  color: #9ea6af;
  background: #fbfbfc;
}

.shape-dot,
.shape-square {
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
}

.shape-dot {
  border-radius: 50%;
  background: var(--mint);
}

.shape-square {
  border-radius: 3px;
}

.stepper {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  overflow: hidden;
}

.stepper button {
  color: #555f6a;
  background: transparent;
  font-size: 20px;
  font-weight: 700;
}

.stepper output {
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-left: 1px solid var(--line);
  font-weight: 850;
}

.control-row {
  grid-template-columns: 1fr 68px;
  align-items: center;
}

.control-row input {
  grid-column: 1 / -1;
}

.control-row output {
  justify-self: end;
  min-width: 58px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  background: #fff;
  font-size: 14px;
  font-weight: 850;
  text-align: center;
}

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

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  margin-bottom: 12px;
}

.switch-row input,
.toolbar-toggle input {
  width: 22px;
  height: 22px;
  accent-color: var(--mint);
}

.generate-button {
  position: static;
  z-index: auto;
  min-height: 42px;
  border: 1px solid var(--mint-dark);
  background: var(--mint);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  box-shadow: none;
}

.generate-button:hover {
  background: var(--mint-dark);
  transform: none;
}

.generate-button:disabled,
.download-button:disabled,
.outline-button:disabled {
  cursor: not-allowed;
  border-color: #d8dde5;
  background: #f1f3f5;
  color: #9aa3ad;
  opacity: 1;
  transform: none;
  box-shadow: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) 72px;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  min-width: 0;
  min-height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar-group {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.tool-tabs {
  min-width: 0;
}

.tool-tab {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid transparent;
  color: #424a55;
  background: #fff;
  font-size: 13px;
}

.tool-tab.is-active,
.tool-tab[aria-pressed="true"] {
  border-color: #c8eee8;
  background: #dff7f3;
  color: var(--mint-dark);
}

.view-tools {
  gap: 16px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.toolbar-toggle,
.zoom-button,
.zoom-slider-control {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: #4e5661;
  font-size: 13px;
  font-weight: 800;
}

.toolbar-toggle input {
  width: 16px;
  height: 16px;
}

.zoom-slider-control {
  min-width: 154px;
  padding: 0 10px;
}

.zoom-slider-control svg {
  color: #4e5661;
}

.zoom-slider-control input {
  width: 72px;
  min-width: 72px;
  accent-color: var(--mint);
  cursor: pointer;
}

.zoom-slider-control output {
  min-width: 40px;
  color: #4e5661;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.zoom-button.square {
  width: 42px;
  padding: 0;
  font-size: 22px;
}

.canvas-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 28px;
  background:
    radial-gradient(circle at 1px 1px, rgba(31, 35, 40, 0.06) 1px, transparent 0),
    #fbfcfd;
  background-size: 20px 20px;
}

.canvas-stage.is-panning,
.canvas-stage.is-panning #patternCanvas {
  cursor: grabbing;
}

#patternCanvas {
  display: none;
  max-width: none;
  max-height: none;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(31, 35, 40, 0.12);
  cursor: crosshair;
  touch-action: none;
  transform-origin: center center;
}

#patternCanvas.is-visible {
  display: block;
}

#patternCanvas.is-transparent {
  background:
    linear-gradient(45deg, #eef2f6 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f6 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2f6 75%),
    linear-gradient(-45deg, transparent 75%, #eef2f6 75%),
    #ffffff;
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

.empty-state {
  display: grid;
  gap: 8px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state[role="button"] {
  cursor: pointer;
}

.empty-state[role="button"]:focus-visible {
  outline: 3px solid rgba(34, 184, 169, 0.22);
  outline-offset: 8px;
}

.empty-state strong {
  color: var(--ink);
  font-size: 20px;
  font-weight: 850;
}

.palette-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.palette-strip strong {
  font-size: 14px;
  font-weight: 850;
}

.palette-strip span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.palette-dots {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
}

.palette-dots.is-expanded {
  flex-wrap: wrap;
  overflow: visible;
}

.palette-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.14);
  padding: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
  cursor: pointer;
}

.palette-dot.is-selected {
  outline: 3px solid rgba(34, 184, 169, 0.38);
  outline-offset: 3px;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    0 0 0 1px var(--mint-dark);
}

.palette-more {
  border: 0;
  background: transparent;
  color: #5d6672;
  font-size: 13px;
  font-weight: 850;
}

.palette-more:disabled {
  color: #a0a8b2;
  cursor: not-allowed;
}

.download-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  min-height: 64px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.download-area .outline-button {
  min-width: 0;
  padding: 0 10px;
  font-size: 13px;
}

.download-button {
  min-height: 42px;
  width: 100%;
  padding: 0 18px;
  border: 1px solid var(--mint-dark);
  background: var(--mint);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  box-shadow: none;
}

.download-button:hover {
  background: var(--mint-dark);
  transform: none;
}

.legend-section {
  padding: 18px 0 16px;
  border-bottom: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.strong-heading small {
  margin-left: -6px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 750;
}

#legendHint {
  color: var(--muted);
  font-size: 14px;
  font-weight: 850;
}

.legend-table {
  overflow: hidden;
}

.legend-head,
.legend-item {
  display: grid;
  grid-template-columns: minmax(74px, 1.1fr) 70px 62px 48px;
  align-items: center;
  gap: 6px;
}

.legend-head {
  min-height: 32px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.legend-list {
  display: grid;
  max-height: min(410px, calc(100vh - 425px));
  margin: 0 0 20px;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.legend-item {
  min-height: 40px;
  border-top: 1px solid var(--line);
  color: #454d57;
  font-size: 14px;
  font-weight: 750;
}

.legend-color {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.swatch {
  display: inline-block;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.14);
}

.legend-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-code,
.legend-count,
.legend-percent {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.info-section {
  padding: 18px 0 16px;
  border-bottom: 1px solid var(--line);
}

.pattern-info {
  display: grid;
  gap: 10px;
  margin: 12px 0 0;
}

.pattern-info div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.pattern-info dt,
.pattern-info dd {
  margin: 0;
  font-size: 14px;
}

.pattern-info dt {
  color: var(--muted);
  font-weight: 750;
}

.pattern-info dd {
  color: #2f3640;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.tip-box {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border-radius: var(--radius);
  background: #fff8f7;
  border: 1px solid var(--line);
  color: #55606b;
}

.tip-box svg {
  color: var(--yellow-dark);
}

.tip-box p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.6;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 30;
  transform: translate(-50%, 20px);
  max-width: min(520px, calc(100vw - 40px));
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.mobile-action-dock {
  display: none;
}

.mobile-preview-meta,
.mobile-export-actions {
  display: none;
}

.help-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.help-dialog::backdrop {
  background: rgba(31, 35, 40, 0.32);
}

.help-dialog-inner {
  padding: 22px;
}

.image-save-dialog {
  width: min(680px, calc(100vw - 24px));
}

.wechat-save-image {
  display: block;
  width: 100%;
  max-height: min(68vh, 760px);
  margin-top: 4px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.help-dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.help-dialog h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
}

.help-dialog ul {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.7;
}

.redemption-dialog {
  width: min(440px, calc(100vw - 32px));
}

.redemption-form {
  display: block;
}

.redemption-form .help-dialog-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.55;
}

.redemption-field {
  margin-top: 20px;
}

.redemption-field input {
  letter-spacing: 0.8px;
  text-transform: uppercase;
}

.redeem-message {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.5;
}

.redeem-message.is-error {
  color: var(--danger-dark);
}

.redeem-message.is-success {
  color: var(--mint-dark);
}

.crop-dialog {
  width: min(780px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-soft);
}

.crop-dialog::backdrop {
  background: rgba(31, 35, 40, 0.36);
}

.crop-dialog-inner {
  padding: 22px;
}

.crop-dialog .help-dialog-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

#cropCanvas {
  display: block;
  width: 100%;
  height: auto;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: grab;
  touch-action: none;
}

#cropCanvas:active {
  cursor: grabbing;
}

.crop-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.crop-controls .control-field,
.crop-controls .control-row {
  margin-bottom: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.dialog-actions .generate-button,
.dialog-actions .outline-button {
  min-height: 40px;
  padding: 0 15px;
}

@media (max-width: 1500px) {
  .tool-tab[data-tool="picker"],
  .tool-tab[data-tool="fill"],
  #fitButton {
    width: 36px;
    padding: 0;
  }

  .tool-tab[data-tool="picker"] span,
  .tool-tab[data-tool="fill"] span,
  #fitButton span {
    display: none;
  }

  .zoom-slider-control {
    min-width: 140px;
  }

  .zoom-slider-control input {
    width: 64px;
    min-width: 64px;
  }
}

@media (max-width: 1360px) {
  body {
    min-width: 1120px;
    overflow: hidden;
  }

  .topbar {
    grid-template-columns: 320px auto minmax(130px, 1fr) auto;
  }

  .topbar-right {
    display: flex;
    gap: 12px;
    padding-right: 16px;
  }

  .app-shell {
    grid-template-columns: 320px minmax(0, 1fr) 340px;
    height: calc(100vh - var(--topbar));
    min-height: 0;
  }

  .summary-panel {
    grid-column: auto;
    border-left: 1px solid var(--line);
    border-top: 0;
  }

  .tool-tab,
  .toolbar-toggle,
  .zoom-button {
    width: 36px;
    padding: 0;
  }

  .tool-tab span,
  .toolbar-toggle span,
  #fitButton span {
    display: none;
  }

  .zoom-slider-control {
    min-width: 150px;
  }
}

@media (max-width: 980px) {
  html,
  body {
    height: auto;
    min-height: 100%;
  }

  body {
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    position: sticky;
    top: 0;
    z-index: 20;
    height: 58px;
    min-height: 58px;
  }

  .brand {
    gap: 9px;
    padding: 0 14px;
    border-right: 0;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    grid-template-columns: repeat(3, 7px);
    gap: 2px;
    padding: 4px;
  }

  .brand-mark i {
    width: 7px;
    height: 7px;
  }

  .brand strong {
    margin: 0;
    font-size: 19px;
  }

  .brand small,
  .topbar-actions span,
  .topbar-history {
    display: none;
  }

  .topbar-actions {
    justify-self: end;
    padding: 0 12px 0 0;
    gap: 4px;
  }

  .topbar-actions .topbar-button {
    width: 40px;
    height: 40px;
    padding: 0;
  }

  #importProjectButton,
  #saveButton,
  #resetButton {
    display: none;
  }

  .topbar-right {
    display: none;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
  }

  .tool-panel,
  .summary-panel {
    width: 100%;
    min-height: auto;
    overflow: visible;
    border: 0;
  }

  .tool-panel {
    order: 1;
    padding: 0;
    border-bottom: 1px solid var(--line);
  }

  .tool-panel-scroll {
    flex: 0 0 auto;
    overflow: visible;
    padding: 16px 16px 0;
  }

  .tool-panel-cta {
    padding: 12px 16px 18px;
  }

  .mobile-settings {
    display: block;
    margin-top: 4px;
  }

  .mobile-settings > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    color: #424a55;
    background: #fff;
    font-size: 14px;
    font-weight: 850;
    cursor: pointer;
    list-style: none;
  }

  .mobile-settings > summary::-webkit-details-marker {
    display: none;
  }

  .mobile-settings > summary::after {
    content: "+";
    color: var(--mint-dark);
    font-size: 22px;
    font-weight: 500;
  }

  .mobile-settings[open] > summary {
    margin-bottom: 16px;
    border-color: #a8e6de;
    color: var(--mint-dark);
    background: var(--surface-mint);
  }

  .mobile-settings[open] > summary::after {
    content: "−";
  }

  .workspace {
    order: 2;
    min-height: 0;
    grid-template-rows: auto minmax(420px, 58svh) auto;
  }

  .editor-toolbar,
  .palette-strip {
    gap: 10px;
    padding: 10px 12px;
  }

  .editor-toolbar {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    flex-wrap: wrap;
    overflow: visible;
  }

  .editor-toolbar::-webkit-scrollbar {
    display: none;
  }

  .tool-tabs,
  .view-tools {
    flex: 0 0 100%;
    flex-wrap: nowrap;
    overflow: visible;
  }

  .view-tools {
    gap: 10px;
    justify-content: space-between;
  }

  .toolbar-group {
    flex-wrap: nowrap;
  }

  .canvas-stage {
    padding: 16px;
    min-height: 0;
    overscroll-behavior: contain;
  }

  .palette-strip {
    grid-template-columns: 1fr auto;
  }

  .palette-dots {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .palette-more {
    justify-self: end;
  }

  .summary-panel {
    order: 3;
    padding: 0 16px 94px;
    border-top: 1px solid var(--line);
  }

  .download-area {
    position: sticky;
    top: 58px;
    z-index: 8;
    margin: 0 -16px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
  }

  .mobile-action-dock {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -8px 20px rgba(31, 35, 40, 0.05);
    backdrop-filter: blur(12px);
  }

  .mobile-action-dock button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 42px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: #fff;
    color: #4e5661;
    font-size: 13px;
    font-weight: 850;
  }

  .mobile-action-dock button:first-child,
  .mobile-action-dock button:last-child {
    border-color: var(--mint-dark);
    background: var(--mint);
    color: #fff;
  }

  .legend-head,
  .legend-item {
    grid-template-columns: minmax(92px, 1fr) 70px 70px 54px;
  }

  .crop-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  html,
  body {
    height: 100%;
    min-height: 100%;
    overscroll-behavior: none;
  }

  body {
    overflow: hidden;
    background: var(--bg);
  }

  .topbar {
    position: relative;
    flex: 0 0 58px;
    box-shadow: 0 1px 0 rgba(82, 52, 66, 0.04);
  }

  .app-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(270px, 45svh) minmax(0, 1fr);
    height: calc(100dvh - 58px);
    min-height: 0;
    overflow: hidden;
    background: var(--bg);
  }

  .workspace {
    grid-row: 1;
    order: initial;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .editor-toolbar {
    display: flex;
    align-items: center;
    min-height: 52px;
    padding: 8px 12px;
    border-bottom: 0;
  }

  .tool-tabs,
  .palette-strip {
    display: none;
  }

  .view-tools {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    width: 100%;
    gap: 8px;
    align-items: center;
  }

  .display-tools,
  .zoom-tools {
    display: flex;
    min-width: 0;
    gap: 6px;
  }

  .zoom-tools {
    justify-content: flex-end;
  }

  .toolbar-toggle {
    width: 42px;
    min-height: 36px;
    padding: 0;
  }

  .toolbar-toggle span,
  #fitButton span {
    display: none;
  }

  .zoom-slider-control {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0 8px;
  }

  .zoom-slider-control input {
    width: 100%;
    min-width: 0;
  }

  .zoom-slider-control output {
    min-width: 38px;
  }

  .zoom-button {
    width: 38px;
    min-width: 38px;
    padding: 0;
  }

  .mobile-preview-meta {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 36px;
    padding: 0 16px 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  .has-pattern .mobile-preview-meta {
    display: flex;
  }

  .mobile-preview-meta > span {
    color: var(--mint-dark);
  }

  .mobile-preview-meta div {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    min-width: 0;
  }

  .mobile-preview-meta strong {
    color: #605562;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .canvas-stage {
    min-height: 0;
    padding: 10px;
    overflow: auto;
    background:
      radial-gradient(circle at 1px 1px, rgba(108, 72, 88, 0.055) 1px, transparent 0),
      #fffdfd;
    background-size: 18px 18px;
  }

  #patternCanvas {
    box-shadow: 0 8px 24px rgba(88, 51, 67, 0.12);
  }

  .empty-state strong {
    font-size: 18px;
  }

  .tool-panel {
    grid-row: 2;
    order: initial;
    display: flex;
    min-height: 0;
    overflow: hidden;
    border: 0;
    background: var(--surface-soft);
  }

  .tool-panel-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 12px 14px 18px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .tool-panel-scroll > .step-section {
    padding: 0 0 12px;
    margin: 0 0 12px;
  }

  .step-heading {
    gap: 8px;
    margin-bottom: 10px;
  }

  .step-badge {
    width: 20px;
    height: 20px;
    font-size: 11px;
    box-shadow: none;
  }

  .step-heading h1,
  .step-heading h2 {
    font-size: 16px;
  }

  .has-pattern .tool-panel-scroll > .step-section {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
  }

  .has-pattern .tool-panel-scroll > .step-section .step-heading {
    margin: 0;
  }

  .has-pattern .tool-panel-scroll > .step-section .upload-zone,
  .has-pattern .tool-panel-scroll > .step-section .source-meta {
    display: none;
  }

  .has-pattern .tool-panel-scroll > .step-section .upload-actions {
    grid-column: 2;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .mobile-settings {
    display: block;
    margin-top: 0;
  }

  .mobile-settings > summary {
    position: sticky;
    top: -12px;
    z-index: 2;
    min-height: 44px;
    margin: 0 -2px 14px;
    border-color: #eac1cf;
    background: #fff7f9;
    box-shadow: 0 8px 12px rgba(252, 247, 249, 0.94);
  }

  .mobile-settings[open] > summary {
    margin-bottom: 14px;
    border-color: #e5afc0;
    color: var(--mint-dark);
    background: #fff0f4;
  }

  .mobile-settings > summary::after {
    color: var(--mint-dark);
  }

  .control-stack .step-section:last-of-type {
    padding-bottom: 8px;
    margin-bottom: 0;
  }

  .tool-panel-cta {
    flex: 0 0 auto;
    padding: 10px 14px max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 253, 253, 0.98);
    box-shadow: 0 -8px 18px rgba(89, 56, 69, 0.05);
  }

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

  .mobile-export-actions .download-button,
  .mobile-export-actions .outline-button {
    min-height: 42px;
    font-size: 13px;
  }

  .tool-panel-cta #generateButton {
    display: none;
  }

  .summary-panel,
  .mobile-action-dock {
    display: none;
  }
}
