:root {
  --blue: #3197ee;
  --cyan: #12b8aa;
  --red: #f05b61;
  --text: #162033;
  --muted: #6f7b8f;
  --line: #dce4ef;
  --panel: #f6f8fb;
  --page-bg: #eef2f7;
  --surface: #fff;
  --surface-soft: #f8fbff;
  --surface-selected: #eaf5ff;
  --input-bg: #fff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: "Microsoft YaHei UI", "Segoe UI", Arial, sans-serif;
  overflow-x: hidden;
}

body.dark-theme {
  --text: #edf5ff;
  --muted: #aebbd0;
  --line: #314055;
  --panel: #111827;
  --page-bg: #0b1220;
  --surface: #172033;
  --surface-soft: #1f2a3d;
  --surface-selected: #173552;
  --input-bg: #0f172a;
}

body.dark-theme button:not(.primary):not(.warn):not(.accent):not(.danger),
body.dark-theme input,
body.dark-theme select,
body.dark-theme textarea {
  border-color: var(--line);
  background-color: var(--input-bg);
  color: var(--text);
}

body.dark-theme input::placeholder,
body.dark-theme textarea::placeholder {
  color: #8291a8;
}

body.dark-theme option {
  background: var(--input-bg);
  color: var(--text);
}

body.dark-theme .top-notice {
  border-color: #244d73;
  background: linear-gradient(90deg, #10243b, #172033);
  color: #8fd0ff;
}

body.dark-theme .canvas-shell {
  background-color: #111827;
  background-image:
    linear-gradient(45deg, #1f2937 25%, transparent 25%),
    linear-gradient(-45deg, #1f2937 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1f2937 75%),
    linear-gradient(-45deg, transparent 75%, #1f2937 75%);
}

body.dark-theme .thumb {
  background-color: #101827;
  background-image:
    linear-gradient(45deg, #243044 25%, transparent 25%),
    linear-gradient(-45deg, #243044 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #243044 75%),
    linear-gradient(-45deg, transparent 75%, #243044 75%);
}

body.dark-theme .thumb-empty,
body.dark-theme .icon-editor-label,
body.dark-theme .gift-card span,
body.dark-theme .gif-preview-panel strong {
  color: var(--muted);
}

body.dark-theme .item-card {
  border-color: #334155;
  background: var(--surface-soft);
}

body.dark-theme .item-card.selected {
  border-color: #38bdf8;
  background: var(--surface-selected);
}

body.dark-theme .color-popover,
body.dark-theme .modal-card,
body.dark-theme .gift-card {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

body.dark-theme .modal-head,
body.dark-theme .modal-foot {
  border-color: var(--line);
  background: #111827;
}

body.dark-theme .gift-picker-tabs,
body.dark-theme .gift-picker-search {
  border-color: var(--line);
  background: #111827;
}

body.dark-theme .modal-head,
body.dark-theme .modal-foot,
body.dark-theme .gift-tabs {
  background: #111827;
}

body.dark-theme .icon-btn {
  color: #c7d2e4;
}

body.dark-theme .gif-preview-stage {
  background:
    linear-gradient(45deg, #1f2937 25%, transparent 25%),
    linear-gradient(-45deg, #1f2937 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1f2937 75%),
    linear-gradient(-45deg, transparent 75%, #1f2937 75%);
  background-color: #111827;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

body.dark-theme .gift-card {
  border-color: var(--line);
  background: #182338;
}

body.dark-theme .gift-card strong {
  color: var(--text);
}

body.dark-theme .gift-image-wp-page,
body.dark-theme .topbar,
body.dark-theme .workspace,
body.dark-theme .config-panel,
body.dark-theme .preview-panel,
body.dark-theme .card,
body.dark-theme .panel-head,
body.dark-theme .section-title,
body.dark-theme .item-list,
body.dark-theme .hint {
  background: var(--page-bg);
  color: var(--text);
}

body.dark-theme .topbar {
  border-bottom: 1px solid var(--line);
}

body.dark-theme .brand span,
body.dark-theme .zoom-control,
body.dark-theme .section-title,
body.dark-theme .form-grid label,
body.dark-theme .item-card label,
body.dark-theme .item-card span,
body.dark-theme .item-fields label,
body.dark-theme .item-bg-controls label,
body.dark-theme .display-options,
body.dark-theme .icon-editor-label {
  color: var(--muted);
}

body.dark-theme .brand strong,
body.dark-theme h2,
body.dark-theme h3,
body.dark-theme .item-title,
body.dark-theme .item-card strong {
  color: var(--text);
}

body.dark-theme .preview-panel,
body.dark-theme .card {
  border-color: var(--line);
  background: #111827;
}

body.dark-theme .panel-head,
body.dark-theme .section-title {
  border-color: var(--line);
  background: #111827;
}

body.dark-theme .item-card {
  border-color: #334155;
  background: #172033;
  color: var(--text);
}

body.dark-theme .item-card.selected {
  border-color: #38bdf8;
  background: #173552;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, .36);
}

body.dark-theme .item-card input,
body.dark-theme .item-card select,
body.dark-theme .item-card textarea,
body.dark-theme .card input,
body.dark-theme .card select,
body.dark-theme .card textarea {
  border-color: #3b4a60;
  background: #0f172a;
  color: #edf5ff;
}

body.dark-theme .toolbar button:not(.primary):not(.warn):not(.accent):not(.danger),
body.dark-theme .section-actions button:not(.primary):not(.warn):not(.accent):not(.danger),
body.dark-theme .item-actions button:not(.primary):not(.warn):not(.accent):not(.danger),
body.dark-theme .gift-select-btn,
body.dark-theme .image-upload-btn,
body.dark-theme .dialog-action:not(.primary) {
  border-color: #3b4a60;
  background: #172033;
  color: #e6eefb;
}

body.dark-theme .toolbar button:not(.primary):not(.warn):not(.accent):not(.danger):hover,
body.dark-theme .section-actions button:not(.primary):not(.warn):not(.accent):not(.danger):hover,
body.dark-theme .item-actions button:not(.primary):not(.warn):not(.accent):not(.danger):hover {
  border-color: #38bdf8;
  background: #1f2a3d;
}

body.dark-theme .thumb,
body.dark-theme .thumb-empty {
  border-color: #3b4a60;
  color: #9fb0c7;
}

body.dark-theme input[type="range"] {
  accent-color: var(--cyan);
}

button,
input,
select {
  font: inherit;
}

button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

button.warn {
  border-color: #ee9923;
  background: #ee9923;
  color: #fff;
}

button.accent {
  border-color: var(--cyan);
  background: var(--cyan);
  color: #fff;
}

button.danger {
  border-color: var(--red);
  background: var(--red);
  color: #fff;
}

button.hint-button,
button.hint-button:disabled {
  border-color: #d9e5f2;
  background: #f4f8fc;
  color: #8a97aa;
  cursor: default;
  opacity: 1;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 0 0 auto;
}

.brand-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand strong {
  font-size: 22px;
}

.theme-toggle {
  width: 26px;
  min-width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  font-size: 15px;
  line-height: 24px;
}

.brand span,
.hint {
  color: var(--muted);
  font-size: 13px;
}

.top-notice {
  flex: 1 1 360px;
  min-width: 180px;
  max-width: 520px;
  height: 34px;
  overflow: hidden;
  border: 1px solid #bfe1ff;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--surface) 82%, var(--blue)), var(--surface));
  color: #0f73c9;
  font-size: 14px;
  font-weight: 700;
  line-height: 32px;
  white-space: nowrap;
}

.top-notice-track {
  display: inline-flex;
  gap: 56px;
  min-width: max-content;
  padding-left: 100%;
  animation: topNoticeScroll 16s linear infinite;
}

.top-notice:hover .top-notice-track {
  animation-play-state: paused;
}

@keyframes topNoticeScroll {
  from {
    transform: translateX(0);
  }
  to {
    transform: translateX(-50%);
  }
}

.toolbar {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, var(--preview-width, 43%)) 10px minmax(460px, 1fr);
  gap: 10px;
  height: calc(100vh - 68px);
  padding: 14px;
}

.workspace.resizing {
  user-select: none;
  cursor: col-resize;
}

.workspace-resizer {
  align-self: stretch;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent 0 35%, #d5deea 35% 65%, transparent 65% 100%);
  cursor: col-resize;
  transition: background .16s ease, box-shadow .16s ease;
}

.workspace-resizer:hover,
.workspace-resizer.active {
  background: linear-gradient(90deg, transparent 0 28%, var(--teal) 28% 72%, transparent 72% 100%);
  box-shadow: 0 0 0 3px rgba(0, 184, 168, .12);
}

.preview-panel,
.config-panel {
  min-width: 0;
}

.preview-panel,
.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.preview-panel {
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.panel-head,
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.preview-actions {
  display: none;
  gap: 8px;
}

.preview-actions button {
  height: 32px;
}

.global-settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.bg-width-setting {
  display: none !important;
}

#globalToggleBtn {
  display: none;
  height: 32px;
  min-width: 70px;
}

h2 {
  margin: 0;
  font-size: 17px;
}

.zoom-control {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.canvas-shell {
  flex: 1;
  min-height: 0;
  overflow: auto;
  scrollbar-width: none;
  display: grid;
  place-items: center;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e9edf3 25%, transparent 25%),
    linear-gradient(-45deg, #e9edf3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9edf3 75%),
    linear-gradient(-45deg, transparent 75%, #e9edf3 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  cursor: grab;
}

.canvas-shell::-webkit-scrollbar {
  display: none;
}

.canvas-shell.panning {
  cursor: grabbing;
}

.mobile-page-scroll-guide {
  display: none;
}

canvas {
  display: block;
  max-width: none;
  background: transparent;
  touch-action: none;
  transition: filter .16s ease, opacity .16s ease;
}

canvas.drag-sorting {
  cursor: grabbing;
  filter: drop-shadow(0 10px 22px rgba(37, 150, 255, .22));
}

.hint {
  margin: 0;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.config-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.card {
  padding: 14px;
}

.grid {
  display: grid;
  gap: 12px;
}

.form-grid {
  grid-template-columns: repeat(16, minmax(0, 1fr));
  align-items: center;
}

label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
  color: var(--text);
}

.form-grid label {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
}

.form-grid label:has(input[type="checkbox"]) {
  display: flex;
}

.form-grid label:nth-child(1),
.form-grid label:nth-child(2) {
  grid-column: span 5;
}

.form-grid label:nth-child(3) {
  grid-column: span 6;
}

.form-grid label:nth-child(4) {
  grid-column: span 5;
}

.form-grid label:nth-child(5),
.form-grid label:nth-child(6) {
  grid-column: span 1;
  gap: 4px;
}

.form-grid label:nth-child(7) {
  grid-column: span 3;
  gap: 4px;
}

.form-grid label:nth-child(8) {
  grid-column: span 3;
  grid-template-columns: 72px auto;
}

.form-grid label:nth-child(9) {
  grid-column: span 3;
}

.form-grid label:nth-child(10) {
  grid-column: span 6;
}

.form-grid label:nth-child(11) {
  grid-column: span 4;
}

.form-grid label:nth-child(12) {
  grid-column: span 3;
  grid-template-columns: 72px auto;
}

.form-grid label:nth-child(13) {
  grid-column: span 6;
}

#strokeColorPicker,
#interferenceColorPicker {
  display: inline-flex;
  align-items: center;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--input-bg);
  color: var(--text);
}

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

input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
}

.color-picker-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  width: 28px;
  height: 28px;
}

.color-swatch-button {
  width: 28px;
  height: 28px;
  min-width: 28px;
  padding: 0;
  border: 1px solid #c9d4e2;
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .78);
}

.color-swatch-button:hover {
  border-color: var(--blue);
}

.color-popover {
  position: fixed;
  z-index: 80;
  display: none;
  width: 228px;
  padding: 8px;
  border: 1px solid #d6dfeb;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(15, 23, 42, .18);
}

.color-popover.open {
  display: block;
}

.color-preset-grid {
  display: grid;
  grid-template-columns: repeat(8, 20px);
  gap: 6px;
}

.color-preset {
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  border: 1px solid rgba(15, 23, 42, .12);
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .42);
}

.color-preset:hover {
  transform: translateY(-1px);
  border-color: var(--blue);
}

.color-custom-preset {
  background:
    linear-gradient(135deg, transparent 0 48%, #ef4444 49% 52%, transparent 53%),
    conic-gradient(from 0deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00);
}

.native-color-input {
  position: absolute;
  inset: 0;
  width: 28px;
  height: 28px;
  opacity: 0;
  pointer-events: none;
}

.mini-check {
  justify-content: center;
  gap: 4px;
  font-size: 13px;
}

.mini-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--cyan);
}

.item-list-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
}

.item-list {
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.item-card {
  position: relative;
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) 86px;
  gap: 12px;
  padding: 34px 12px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.item-card.can-drag {
  cursor: move;
}

.item-card.can-drag input,
.item-card.can-drag button,
.item-card.can-drag select,
.item-card.can-drag textarea,
.item-card.can-drag label {
  cursor: auto;
}

.item-card.dragging {
  opacity: .55;
  cursor: grabbing;
}

.item-card.drag-over {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(47, 147, 255, .18);
}

.item-card.selected {
  border-color: var(--blue);
  background: var(--surface-selected);
}

.thumb-wrap {
  position: relative;
  width: 76px;
  height: 76px;
}

.thumb {
  width: 76px;
  height: 76px;
  border: 1px dashed #c7d1df;
  border-radius: 8px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #e9edf3 25%, transparent 25%),
    linear-gradient(-45deg, #e9edf3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e9edf3 75%),
    linear-gradient(-45deg, transparent 75%, #e9edf3 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  cursor: pointer;
}

.thumb-clear {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  min-width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #ff5c67;
  color: #fff;
  font-size: 18px;
  line-height: 20px;
  font-weight: 700;
  box-shadow: 0 3px 10px rgba(239, 68, 68, .3);
}

.thumb-clear:hover {
  background: #ef4444;
}

.thumb img {
  max-width: 100%;
  max-height: 100%;
}

.thumb-empty {
  padding: 0 6px;
  color: #7b8798;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.2;
  text-align: center;
}

.thumb-tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.thumb-tools-primary {
  grid-column: 1;
}

.thumb-tools-secondary {
  grid-column: 3;
}

.icon-editor {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.icon-editor-label {
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
}

.gift-select-btn {
  width: 76px;
  height: 28px;
  padding: 0;
  border-color: var(--cyan);
  background: var(--cyan);
  color: #fff;
  font-size: 13px;
}

.image-upload-btn {
  width: 76px;
  height: 28px;
  padding: 0;
  border-color: #2f9dea;
  background: #2f9dea;
  color: #fff;
  font-size: 13px;
}

.item-fields {
  grid-column: 2;
  display: grid;
  grid-template-columns: 56px 1fr 48px 72px 44px 72px 44px;
  gap: 8px;
  align-items: center;
}

.item-bg-controls {
  grid-column: 2 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.item-display-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.item-display-controls input[type="range"] {
  width: 116px;
  flex: 0 0 116px;
}

.item-actions {
  position: absolute;
  top: 7px;
  right: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.item-actions button {
  min-width: 42px;
  height: 22px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 20px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, .32);
}

.modal-card {
  width: 396px;
  max-width: calc(100vw - 28px);
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 56px rgba(15, 23, 42, .28);
}

.gif-modal-card {
  width: 760px;
}

.modal-head {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 16px;
  background: #e5ebf4;
}

.modal-head h2 {
  font-size: 18px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #8c94a0;
  font-size: 22px;
}

.modal-body {
  display: grid;
  gap: 16px;
  padding: 24px 20px 20px 28px;
}

.gif-modal-body {
  grid-template-columns: 360px minmax(0, 1fr);
  align-items: stretch;
  padding: 22px;
}

.gif-settings {
  display: grid;
  gap: 16px;
}

.gif-preview-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.gif-preview-panel strong {
  color: #1c2634;
  font-size: 14px;
}

.gif-preview-stage {
  flex: 0 0 auto;
  min-height: 0;
  max-width: 100%;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(-45deg, #eef2f7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef2f7 75%),
    linear-gradient(-45deg, transparent 75%, #eef2f7 75%);
  background-color: #fff;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

#gifPreviewCanvas,
#gifResultPreview {
  display: block;
  max-width: 100%;
  height: auto;
}

#gifPreviewCanvas {
  max-width: 100%;
  max-height: 232px;
  width: auto;
  height: auto;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}

#gifResultPreview {
  max-width: 100%;
  max-height: 232px;
  width: auto;
  height: auto;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}

.dialog-row {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 8px 12px;
  align-items: center;
}

.dialog-row input[type="range"] {
  min-width: 0;
}

.dialog-row em {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.dialog-row.compact {
  grid-template-columns: 76px 1fr;
}

.dialog-row.compact select {
  grid-column: 2;
}

.modal-foot {
  height: 78px;
  display: grid;
  grid-template-columns: 1fr 120px 120px;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  background: #f8fafc;
}

#gifStatusText {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

.modal-foot button {
  width: 100%;
}

.dialog-action {
  height: 42px;
  min-width: 110px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  line-height: 1;
  font-weight: 700;
  text-align: center;
}

.gift-picker-card {
  width: 792px;
  height: 760px;
  max-height: calc(100vh - 34px);
  display: flex;
  flex-direction: column;
}

.gift-picker-body {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 14px;
  padding: 14px;
}

.gift-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px 16px;
  border-radius: 8px;
  background: #f5f7fa;
}

.gift-tabs button {
  height: 34px;
  border-radius: 17px;
  padding: 0 16px;
}

.gift-tabs button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.gift-grid {
  min-height: 0;
  flex: 1;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 12px;
  padding: 2px 4px 8px;
}

.gift-card {
  position: relative;
  height: 144px;
  padding: 18px 10px 10px;
  border: 1px solid #dce4ef;
  border-radius: 6px;
  background: var(--surface);
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 8px;
}

.gift-card:hover {
  border-color: var(--blue);
  box-shadow: 0 6px 20px rgba(49, 151, 238, .16);
}

.gift-card img {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.gift-card strong,
.gift-card span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gift-card strong {
  color: #263245;
  font-size: 14px;
}

.gift-card span {
  color: #8a94a3;
  font-size: 12px;
}

.gift-badge {
  position: absolute;
  top: 0;
  left: 0;
  padding: 2px 7px;
  border-radius: 4px 0 4px 0;
  background: #b72bd5;
  color: #fff;
  font-size: 12px;
}

.gift-picker-foot {
  grid-template-columns: 1fr 92px;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
  }

  .workspace-resizer {
    display: none;
  }

  .preview-panel {
    min-height: 540px;
  }
}

@media (max-width: 760px) {
  body {
    min-width: 0;
  }

  button {
    min-width: 0;
    height: 38px;
    padding: 0 10px;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    min-height: 0;
    padding: 12px;
  }

  .topbar > * {
    min-width: 0;
  }

  .brand {
    flex-direction: row;
    align-items: baseline;
    justify-content: flex-start;
  }

  .brand strong {
    font-size: 20px;
  }

  .brand span {
    display: none;
  }

  .top-notice {
    width: 100%;
    max-width: none;
    min-width: 0;
    height: 30px;
    font-size: 13px;
    line-height: 28px;
  }

  .toolbar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
    min-width: 0;
  }

  .toolbar button {
    width: 100%;
    padding: 0 6px;
    font-size: 12px;
    white-space: nowrap;
  }

  .workspace {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 10px;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .config-panel {
    display: contents;
  }

  .config-panel > .card:first-child {
    order: 1;
  }

  .preview-panel {
    order: 2;
  }

  .config-panel > .item-list-card {
    order: 3;
  }

  .preview-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 430px;
    width: 100%;
    max-width: 100%;
  }

  .panel-head,
  .section-title {
    align-items: flex-start;
    padding: 12px;
    min-width: 0;
  }

  .panel-head {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
  }

  .panel-head h2 {
    grid-column: 1;
  }

  .preview-actions {
    display: flex;
    grid-column: 2;
    justify-content: end;
  }

  .zoom-control {
    grid-column: 1 / -1;
    width: 100%;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    min-width: 0;
    overflow: hidden;
  }

  .zoom-control input {
    display: block;
    min-width: 0;
    width: 100%;
    max-width: 100%;
  }

  .canvas-shell {
    grid-row: 2;
    grid-column: 1;
    min-height: 320px;
    place-items: start center;
    padding: 10px 0;
    overscroll-behavior: contain;
    touch-action: none;
  }

  .mobile-page-scroll-guide {
    grid-row: 2;
    grid-column: 1;
    justify-self: end;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 48px;
    margin: 8px 4px 8px 0;
    padding-top: 18px;
    border: 2px solid rgba(255, 92, 103, .96);
    border-radius: 8px 0 0 8px;
    background: linear-gradient(180deg, rgba(255, 92, 103, .22), rgba(255, 92, 103, .08));
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .62), 0 8px 20px rgba(255, 92, 103, .22);
    color: #d93647;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0;
    writing-mode: vertical-rl;
    text-align: center;
    position: relative;
    z-index: 12;
    pointer-events: auto;
    touch-action: pan-y;
    cursor: ns-resize;
    user-select: none;
  }

  body.dark-theme .mobile-page-scroll-guide {
    background: linear-gradient(180deg, rgba(255, 92, 103, .38), rgba(255, 92, 103, .16));
    box-shadow: 0 0 0 2px rgba(11, 20, 36, .72), 0 8px 20px rgba(255, 92, 103, .26);
    color: #ffdce1;
  }

  canvas {
    touch-action: none;
  }

  body[data-mode="horizontal"] .preview-panel {
    min-height: 245px;
  }

  body[data-mode="horizontal"] .canvas-shell {
    min-height: 150px;
    max-height: 170px;
  }

  .hint {
    grid-row: 3;
    grid-column: 1;
    padding: 8px 12px;
    font-size: 12px;
  }

  .card {
    padding: 12px;
  }

  .global-settings-card .form-grid {
    display: none;
  }

  .global-settings-card.expanded .form-grid {
    display: grid;
  }

  #globalToggleBtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .form-grid label {
    grid-column: 1 / -1;
  }

  .form-grid label,
  .dialog-row,
  .dialog-row.compact {
    grid-template-columns: 76px minmax(0, 1fr);
  }

  .section-title {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  .section-title h2 {
    display: none;
  }

  .section-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 6px;
  }

  .section-actions button {
    width: 100%;
    height: 32px;
    padding: 0 4px;
    font-size: 12px;
  }

  #addBtn,
  #clearBtn {
    display: none;
  }

  .item-list {
    padding: 10px;
    padding-bottom: min(56dvh, 430px);
    overflow-y: auto;
    max-height: min(72dvh, 620px);
    overscroll-behavior: contain;
  }

  .item-card {
    grid-template-columns: 72px minmax(0, 1fr) 72px;
    gap: 10px;
    padding: 10px;
    align-items: start;
  }

  .thumb-tools-primary {
    grid-column: 1;
    grid-row: 1;
  }

  .thumb-tools-secondary {
    grid-column: 3;
    grid-row: 1;
  }

  .thumb,
  .gift-select-btn,
  .image-upload-btn {
    width: 68px;
  }

  .thumb {
    height: 68px;
  }

  .gift-select-btn,
  .image-upload-btn {
    height: 28px;
    font-size: 12px;
  }

  .item-fields {
    grid-column: 1 / -1;
    grid-row: 1;
    grid-template-columns: 42px 58px 32px minmax(0, 1fr);
    gap: 8px 6px;
    box-sizing: border-box;
    padding: 0 78px;
    pointer-events: none;
  }

  .item-fields input,
  .item-fields select,
  .item-fields button,
  .item-fields label,
  .item-fields .color-picker-wrap,
  .item-fields .item-bg-controls,
  .item-fields .mini-check {
    pointer-events: auto;
  }

  .item-fields > span:nth-of-type(1) {
    grid-column: 1;
    grid-row: 1;
  }

  .item-fields > input:nth-of-type(1) {
    grid-column: 2 / -1;
    grid-row: 1;
  }

  .item-fields > span:nth-of-type(2) {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
  }

  .item-fields > input:nth-of-type(2) {
    grid-column: 2;
    grid-row: 2;
  }

  .item-fields > span:nth-of-type(3) {
    display: none;
  }

  .item-fields > .color-picker-wrap:nth-of-type(1) {
    grid-column: 3;
    grid-row: 2;
  }

  .item-fields > span:nth-of-type(4) {
    display: none;
  }

  .item-fields > span:nth-of-type(5) {
    grid-column: 1;
    grid-row: 3;
  }

  .item-fields > input:nth-of-type(3) {
    grid-column: 2 / -1;
    grid-row: 3;
  }

  .item-fields > span:nth-of-type(6) {
    grid-column: 1;
    grid-row: 4;
    justify-self: start;
  }

  .item-fields > input:nth-of-type(4) {
    grid-column: 2;
    grid-row: 4;
  }

  .item-fields > span:nth-of-type(7) {
    display: none;
  }

  .item-fields > .color-picker-wrap:nth-of-type(2) {
    grid-column: 3;
    grid-row: 4;
  }

  .item-fields > span:nth-of-type(8) {
    display: none;
  }

  .item-fields > span:nth-of-type(9) {
    display: none;
  }

  .item-display-controls {
    display: contents;
  }

  .item-display-controls > span:nth-of-type(1) {
    grid-column: 3;
    grid-row: 1;
    white-space: nowrap;
  }

  .item-display-controls > input[type="range"] {
    grid-column: 4 / -1;
    grid-row: 1;
  }

  .item-display-controls > span:nth-of-type(2) {
    grid-column: 1;
    grid-row: 2;
    white-space: nowrap;
  }

  .item-display-controls > .mini-check {
    grid-row: 2;
  }

  .item-bg-controls {
    grid-column: 1 / -1;
    grid-row: 5;
    display: grid;
    grid-template-columns: 38px 62px 70px minmax(0, 1fr);
    grid-template-rows: minmax(34px, auto) minmax(34px, auto);
    align-items: center;
    gap: 8px 8px;
    min-width: 0;
    width: calc(100% + 92px);
    transform: translateX(-78px);
  }

  .item-bg-controls::before {
    content: "背景";
    grid-column: 1;
    grid-row: 1;
    color: var(--text);
  }

  .item-bg-controls > .color-picker-wrap {
    grid-column: 2;
    grid-row: 1;
  }

  .item-bg-controls .mini-check:nth-of-type(1) {
    grid-column: 2;
  }

  .item-bg-controls .mini-check:nth-of-type(2) {
    grid-column: 3;
  }

  .item-bg-controls .mini-check:nth-of-type(3) {
    grid-column: 4;
  }

  .item-display-controls input[type="range"] {
    width: 100%;
    flex: 1 1 auto;
  }

  .item-actions {
    position: static;
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: stretch;
  }

  .item-actions button {
    flex: 1;
  }

  .modal {
    align-items: stretch;
    justify-items: stretch;
  }

  .modal-card,
  .gif-modal-card,
  .gift-picker-card {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .modal-head {
    height: 52px;
  }

  .gif-modal-body {
    grid-template-columns: 1fr;
    overflow: auto;
    padding: 14px;
  }

  .gif-preview-stage {
    min-height: 210px;
  }

  #gifPreviewCanvas,
  #gifResultPreview {
    max-height: 210px;
  }

  .modal-foot {
    height: auto;
    grid-template-columns: 1fr 96px 96px;
    gap: 8px;
    padding: 12px;
  }

  .dialog-action {
    min-width: 0;
    padding: 0 10px;
  }

  .gift-picker-body {
    padding: 12px;
  }

  .gift-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding: 10px;
  }

  .gift-tabs button {
    flex: 0 0 auto;
  }

  .gift-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .gift-card {
    height: 124px;
    padding: 16px 6px 8px;
  }

  .gift-card img {
    width: 48px;
    height: 48px;
  }

  .gift-card strong {
    font-size: 13px;
  }
}

@media (max-width: 420px) {
  .preview-panel {
    min-height: 390px;
  }

  .canvas-shell {
    min-height: 285px;
  }

  body[data-mode="horizontal"] .preview-panel {
    min-height: 230px;
  }

  body[data-mode="horizontal"] .canvas-shell {
    min-height: 140px;
    max-height: 155px;
  }

  .item-card {
    grid-template-columns: 68px minmax(0, 1fr) 68px;
  }

  .thumb-tools {
    display: flex;
    justify-items: center;
  }

  .thumb,
  .gift-select-btn,
  .image-upload-btn {
    width: 100%;
  }

  .item-fields {
    grid-column: 1 / -1;
    grid-template-columns: 42px 50px 28px minmax(0, 1fr);
    padding: 0 74px;
  }

  .item-bg-controls {
    width: calc(100% + 85px);
    transform: translateX(-74px);
  }

  .section-actions {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 4px;
  }

  .section-actions button {
    font-size: 11px;
    padding: 0 2px;
  }

  .gift-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
