* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) fixed;
  color: #333;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
/* ── Header ─────────────────────────────────────────────────── */
.header {
  background: #fff;
  color: #333;
  padding: .6rem 2rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 1px 0 #e8eaf0, 0 2px 12px rgba(0,0,0,.06);
}
.header-logo {
  height: 40px;
  width: auto;
  flex-shrink: 0;
}
.header-divider {
  width: 1px;
  height: 28px;
  background: #e0e4f0;
  flex-shrink: 0;
}
.header .sub { font-size: 0.84rem; color: #888; white-space: nowrap; }
.header .icon { font-size: 1.5rem; }
.header h1 { font-size: 1.35rem; font-weight: 700; }

/* ── Layout ─────────────────────────────────────────────────── */
.container {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.25rem;
  padding: 1.5rem 2rem;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  align-items: start;
  box-sizing: border-box;
}

/* ── Panel / Card ────────────────────────────────────────────── */
.panel {
  background: #fff;
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: 0 2px 10px rgba(0,0,0,.06);
}
.panel h2 {
  font-size: .82rem;
  font-weight: 700;
  color: #667eea;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .9rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid #f0f2f8;
  display: flex;
  align-items: center;
  gap: .4rem;
}

/* ── Upload zone ─────────────────────────────────────────────── */
.upload-zone {
  border: 2px dashed #c5cae9;
  border-radius: 12px;
  padding: 1.4rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .15s;
  background: #fafbff;
  margin-bottom: .9rem;
  user-select: none;
  touch-action: manipulation;
}
.upload-zone:hover, .upload-zone.drag-over {
  border-color: #667eea;
  background: #eef0fb;
  transform: scale(1.01);
}
.upload-zone .icon { font-size: 2.2rem; margin-bottom: .4rem; }
.upload-zone p { font-size: .83rem; color: #888; line-height: 1.5; }
.upload-zone p strong { color: #667eea; }
#file-input { display: none; }

#img-preview {
  width: 100%;
  border-radius: 10px;
  margin-bottom: .75rem;
  display: none;
  max-height: 180px;
  object-fit: contain;
  background: #f0f2f8;
  cursor: pointer;
  transition: opacity .2s, outline .2s;
}
#img-preview:hover {
  opacity: .82;
  outline: 2.5px dashed #667eea;
  outline-offset: 3px;
}

/* ── Form controls ───────────────────────────────────────────── */
.form-group { margin-bottom: .9rem; }
.form-group > label:first-child {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: #666;
  margin-bottom: .38rem;
}

/* Size buttons */
.size-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem;
}
.size-btn {
  padding: .48rem .3rem;
  border: 1.5px solid #e2e4f0;
  border-radius: 8px;
  background: #fff;
  font-size: .82rem;
  cursor: pointer;
  text-align: center;
  transition: all .15s;
  color: #555;
  min-height: 36px;
  touch-action: manipulation;
  user-select: none;
}
.size-btn:hover { border-color: #667eea; color: #667eea; background: #f5f6ff; }
.size-btn.active {
  border-color: #667eea;
  background: #667eea;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(102,126,234,.3);
}
/* 自定义 button spans both columns */
.size-btn[data-w="0"] { grid-column: span 2; }

.custom-size {
  display: none;
  gap: .4rem;
  align-items: center;
  margin-top: .5rem;
}
.custom-size input {
  width: 64px;
  border: 1.5px solid #e2e4f0;
  border-radius: 6px;
  padding: .35rem .4rem;
  font-size: .85rem;
  text-align: center;
  transition: border-color .15s;
  outline: none;
}
.custom-size input:focus { border-color: #667eea; }
.custom-size span { font-size: .85rem; color: #888; }

/* Select */
select {
  width: 100%;
  border: 1.5px solid #e2e4f0;
  border-radius: 8px;
  padding: .46rem .65rem;
  font-size: .85rem;
  color: #444;
  background: #fff;
  outline: none;
  transition: border-color .15s;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .7rem center;
  padding-right: 2.2rem;
}
select:focus { border-color: #667eea; }

/* Range slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #e2e4f0;
  border-radius: 2px;
  border: none;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #667eea;
  cursor: pointer;
  box-shadow: 0 1px 5px rgba(102,126,234,.45);
  transition: box-shadow .15s;
}
input[type="range"]::-webkit-slider-thumb:hover {
  box-shadow: 0 1px 8px rgba(102,126,234,.6);
}
input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #667eea;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 5px rgba(102,126,234,.45);
}

.range-wrap { display: flex; align-items: center; gap: .6rem; }
.range-wrap input { flex: 1; }
.range-val {
  min-width: 28px;
  text-align: center;
  font-size: .88rem;
  font-weight: 700;
  color: #667eea;
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .68rem 1.2rem;
  border-radius: 10px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .18s;
  user-select: none;
  touch-action: manipulation;
}
.btn-primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  width: 100%;
  box-shadow: 0 4px 14px rgba(102,126,234,.35);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(102,126,234,.5); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(102,126,234,.3); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-download {
  background: #fff;
  border: 1.5px solid #667eea;
  color: #667eea;
  padding: .52rem 1rem;
  font-size: .85rem;
  border-radius: 8px;
}
.btn-download:hover { background: #667eea; color: #fff; }
.btn-download.svg { border-color: #10b981; color: #10b981; }
.btn-download.svg:hover { background: #10b981; color: #fff; }
.btn-download.pdf { border-color: #764ba2; color: #764ba2; }
.btn-download.pdf:hover { background: #764ba2; color: #fff; }
.btn-download.csv-list { border-color: #f59e0b; color: #f59e0b; }
.btn-download.csv-list:hover { background: #f59e0b; color: #fff; }

/* ── Preview tabs ────────────────────────────────────────────── */
.preview-tabs {
  display: flex;
  gap: .35rem;
  margin-bottom: .6rem;
  align-items: center;
  flex-wrap: wrap;
}
.codes-toggle-label {
  display: flex;
  align-items: center;
  gap: .3rem;
  margin-left: auto;
  font-size: .76rem;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  user-select: none;
  padding: .22rem .55rem;
  border: 1.5px solid #e2e4f0;
  border-radius: 20px;
  background: #fff;
  transition: border-color .15s, color .15s;
}
.codes-toggle-label:has(input:checked) {
  border-color: #667eea;
  color: #667eea;
  background: #f5f6ff;
}
.codes-toggle-label input[type="checkbox"] {
  width: 13px;
  height: 13px;
  accent-color: #667eea;
  cursor: pointer;
  flex-shrink: 0;
}
.preview-tab-btn {
  padding: .28rem .75rem;
  border: 1.5px solid #e2e4f0;
  border-radius: 20px;
  background: #fff;
  font-size: .78rem;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  transition: all .15s;
  user-select: none;
}
.preview-tab-btn:hover { border-color: #667eea; color: #667eea; }
.preview-tab-btn.active {
  border-color: #667eea;
  background: #667eea;
  color: #fff;
}

/* ── Preview area ────────────────────────────────────────────── */
.preview-area { display: flex; flex-direction: column; gap: 1.25rem; }

.canvas-wrap {
  overflow: auto;
  border-radius: 10px;
  background: #f8f8fc;
  border: 1.5px solid #e8e8f4;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.canvas-wrap canvas { display: block; image-rendering: pixelated; max-width: 100%; }

.placeholder {
  text-align: center;
  color: #bbb;
  padding: 2.5rem 1.5rem;
}
.placeholder .icon { font-size: 3.5rem; margin-bottom: .75rem; }
.placeholder p { font-size: .88rem; line-height: 1.6; }
.placeholder-icon { font-size: 3rem; margin-bottom: .6rem; }
.placeholder-title {
  font-size: .95rem;
  font-weight: 700;
  color: #ccc;
  margin-bottom: 1rem;
}
.placeholder-steps {
  list-style: none;
  counter-reset: steps;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin: 0 auto .9rem;
  text-align: left;
  max-width: 210px;
}
.placeholder-steps li {
  counter-increment: steps;
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: #bbb;
}
.placeholder-steps li::before {
  content: counter(steps);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ebebf5;
  color: #999;
  font-size: .7rem;
  font-weight: 700;
  flex-shrink: 0;
}
.placeholder-tip {
  font-size: .76rem;
  color: #bbb;
  background: #f8f9ff;
  border-radius: 8px;
  padding: .4rem .7rem;
  display: inline-block;
}

/* ── Loading ─────────────────────────────────────────────────── */
.loading {
  display: none;
  text-align: center;
  padding: 3rem 1.5rem;
}
.spinner {
  width: 42px; height: 42px;
  border: 4px solid #e0e0f0;
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin .75s linear infinite;
  margin: 0 auto .9rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { color: #888; font-size: .9rem; }

/* ── Rematch bar ─────────────────────────────────────────────── */
.rematch-bar {
  margin-top: .75rem;
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.btn-rematch {
  padding: .45rem .9rem;
  border: 1.5px solid #667eea;
  border-radius: 8px;
  background: #fff;
  color: #667eea;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.btn-rematch:hover { background: #667eea; color: #fff; }
.btn-rematch:disabled { opacity: .6; cursor: not-allowed; }
.btn-clear-exclude {
  padding: .45rem .75rem;
  border: 1.5px solid #e2e4f0;
  border-radius: 8px;
  background: #fff;
  color: #999;
  font-size: .82rem;
  cursor: pointer;
  transition: all .15s;
}
.btn-clear-exclude:hover { border-color: #e53935; color: #e53935; }

/* ── Brand convert bar ───────────────────────────────────────── */
.brand-convert-bar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: .7rem;
  flex-wrap: wrap;
}
.brand-convert-label { font-size: .8rem; color: #888; white-space: nowrap; }
.brand-convert-bar select {
  width: auto;
  padding: .3rem .5rem;
  font-size: .82rem;
  border-radius: 6px;
  flex: 1;
  min-width: 140px;
  max-width: 200px;
}

/* ── Palette legend ──────────────────────────────────────────── */
.palette-legend { display: none; }
.palette-legend h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .85rem;
  flex-wrap: wrap;
  gap: .3rem;
}
.legend-total {
  font-size: .78rem;
  font-weight: 500;
  color: #999;
  margin-left: auto;
}
.legend-total strong { color: #444; font-weight: 700; }
.brand-badge {
  margin-left: .5rem;
  padding: .15rem .5rem;
  border-radius: 20px;
  background: #eef0fb;
  color: #667eea;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .04em;
  border: 1px solid #d0d4f7;
}

.legend-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .55rem .5rem;
}
.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .28rem;
  cursor: pointer;
  position: relative;
  transition: opacity .15s;
}
.legend-item.excluded { opacity: .35; }
.legend-chip {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .82rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.35);
  letter-spacing: .02em;
  position: relative;
  transition: transform .15s, box-shadow .15s;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
}
.legend-item:hover .legend-chip {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,.18);
}
/* exclude overlay button */
.btn-exclude-color {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  font-size: .62rem;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  display: none;
  z-index: 1;
}
.legend-item:hover .btn-exclude-color { display: block; }
.legend-item.excluded .btn-exclude-color { display: block; background: #667eea; }
.legend-count {
  font-size: .72rem;
  color: #777;
  font-weight: 500;
  line-height: 1;
}
/* dark chip text for very light colors */
.legend-chip.dark-text {
  color: #333;
  text-shadow: none;
}

/* ── Download bar ────────────────────────────────────────────── */
.download-bar {
  display: none;
  flex-direction: column;
  gap: .45rem;
  margin-top: 1rem;
}
.download-bar > span { font-size: .83rem; color: #999; }
.download-primary {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}
.download-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: .38rem;
  padding-top: .4rem;
  border-top: 1px solid #f0f2f8;
}
.btn-dl-main {
  flex: 1;
  min-width: 80px;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: #fff;
  border: none;
  padding: .6rem .7rem;
  font-size: .86rem;
  font-weight: 700;
  border-radius: 9px;
  cursor: pointer;
  transition: all .18s;
  box-shadow: 0 3px 10px rgba(102,126,234,.3);
}
.btn-dl-main:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(102,126,234,.45); }
.btn-dl-main:active { transform: none; box-shadow: none; }
.btn-dl-main.pdf {
  background: linear-gradient(135deg, #764ba2, #5a3d8a);
  box-shadow: 0 3px 10px rgba(118,75,162,.3);
}
.btn-dl-main.pdf:hover { box-shadow: 0 5px 14px rgba(118,75,162,.45); }
.btn-dl-main.svg {
  background: linear-gradient(135deg, #10b981, #059669);
  box-shadow: 0 3px 10px rgba(16,185,129,.3);
}
.btn-dl-main.svg:hover { box-shadow: 0 5px 14px rgba(16,185,129,.45); }
.btn-dl-sec {
  background: #fff;
  border: 1.5px solid #e2e4f0;
  color: #666;
  padding: .4rem .7rem;
  font-size: .8rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all .15s;
}
.btn-dl-sec:hover { border-color: #667eea; color: #667eea; background: #f5f6ff; }

/* ── Edit grid button ────────────────────────────────────────── */
.btn-edit-grid {
  background: #fff;
  border: 1.5px solid #667eea;
  color: #667eea;
  padding: .52rem 1rem;
  font-size: .85rem;
  border-radius: 8px;
}
.btn-edit-grid:hover { background: #667eea; color: #fff; }
.btn-edit-grid.active { background: #667eea; color: #fff; font-weight: 700; }

/* ── Edit toolbar ────────────────────────────────────────────── */
.edit-toolbar {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .5rem;
  padding: .45rem .7rem;
  background: #eef0fb;
  border-radius: 8px;
  border: 1px solid #d0d4f5;
}
.edit-toolbar-label { font-size: .8rem; font-weight: 700; color: #667eea; flex: 1; }
.btn-undo, .btn-reset-grid {
  padding: .3rem .75rem;
  border: 1.5px solid #667eea;
  border-radius: 6px;
  background: #fff;
  color: #667eea;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.btn-undo:hover, .btn-reset-grid:hover { background: #667eea; color: #fff; }
.btn-reset-grid { border-color: #e53935; color: #e53935; }
.btn-reset-grid:hover { background: #e53935; color: #fff; }

/* ── Color picker popover ────────────────────────────────────── */
.color-picker-popover {
  position: absolute;
  z-index: 200;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: .75rem;
  width: 260px;
  border: 1px solid #e2e4f0;
}
.color-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .5rem;
  font-size: .82rem;
  font-weight: 700;
  color: #333;
}
.color-picker-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: #aaa;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}
.color-picker-close:hover { color: #e53935; }
.color-picker-swatches, .color-picker-full-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 160px;
  overflow-y: auto;
}
.cp-swatch {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  border: 1.5px solid rgba(0,0,0,.12);
  cursor: pointer;
  transition: transform .1s, box-shadow .1s;
  flex-shrink: 0;
  position: relative;
}
.cp-swatch:hover { transform: scale(1.18); box-shadow: 0 2px 8px rgba(0,0,0,.2); z-index: 1; }
.btn-expand-palette {
  margin-top: .5rem;
  width: 100%;
  background: #f5f6ff;
  border: 1.5px solid #e2e4f0;
  border-radius: 6px;
  padding: .3rem .5rem;
  font-size: .76rem;
  color: #667eea;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s;
}
.btn-expand-palette:hover { background: #eef0fb; }

/* Canvas crosshair in edit mode */
.canvas-wrap.edit-active { cursor: crosshair; }

/* Edit mode: collapse left panel, expand canvas area */
.container.edit-mode {
  grid-template-columns: 0 1fr;
  gap: 0;
}
.container.edit-mode aside {
  overflow: hidden;
  width: 0;
  min-width: 0;
  opacity: 0;
  pointer-events: none;
  transition: width .25s ease, opacity .2s ease;
}
.container aside {
  transition: width .25s ease, opacity .2s ease;
}
.canvas-wrap.edit-active {
  min-height: 520px;
}

/* ── Param restored hint ─────────────────────────────────────── */
.param-restored-hint {
  display: none;
  position: fixed;
  bottom: 1.5rem; left: 50%;
  transform: translateX(-50%);
  background: #667eea;
  color: #fff;
  padding: .55rem 1.1rem;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(102,126,234,.35);
  z-index: 1000;
  white-space: nowrap;
}

/* ── Board split panel ───────────────────────────────────────── */
.btn-board-split {
  background: #fff;
  border: 1.5px solid #10b981;
  color: #10b981;
  padding: .52rem 1rem;
  font-size: .85rem;
  border-radius: 8px;
}
.btn-board-split:hover { background: #10b981; color: #fff; }
.btn-board-split.active { background: #10b981; color: #fff; font-weight: 700; }

.board-split-panel {
  margin-top: .6rem;
  padding: .65rem .85rem;
  background: #f0fdf8;
  border: 1.5px solid #a7f3d0;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.board-split-row {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  font-size: .83rem;
  color: #444;
}
.board-split-label { font-weight: 600; color: #059669; }
.board-input {
  width: 56px;
  border: 1.5px solid #a7f3d0;
  border-radius: 6px;
  padding: .28rem .4rem;
  font-size: .85rem;
  text-align: center;
  outline: none;
  transition: border-color .15s;
}
.board-input:focus { border-color: #10b981; }
.board-count-info {
  font-size: .78rem;
  color: #059669;
  font-weight: 600;
  margin-left: .3rem;
}
.btn-dl-boards {
  background: #10b981;
  color: #fff;
  border: none;
  padding: .48rem 1rem;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  align-self: flex-start;
}
.btn-dl-boards:hover { background: #059669; }

/* ── Error toast ─────────────────────────────────────────────── */
.toast {
  display: none;
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  background: #e53935;
  color: #fff;
  padding: .75rem 1.25rem;
  border-radius: 10px;
  font-size: .88rem;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  z-index: 1000;
  max-width: 340px;
  animation: toastIn .25s ease;
}
@keyframes toastIn {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

/* ── Pixel mode buttons ──────────────────────────────────────── */
.mode-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .4rem;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .65rem .4rem;
  border: 1.5px solid #e2e4f0;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
  touch-action: manipulation;
  user-select: none;
}
.mode-btn:hover { border-color: #667eea; background: #f5f6ff; }
.mode-btn.active {
  border-color: #667eea;
  background: #eef0fb;
  box-shadow: 0 2px 8px rgba(102,126,234,.15);
}
.mode-icon  { font-size: 1.2rem; margin-bottom: .2rem; }
.mode-label { font-size: .8rem; font-weight: 700; color: #444; }
.mode-desc  { font-size: .7rem; color: #aaa; line-height: 1.3; margin-top: .12rem; }
.mode-btn.active .mode-label { color: #667eea; }

/* ── AI style preset buttons ─────────────────────────────────── */
.ai-style-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .38rem;
  margin-top: .38rem;
}
.ai-style-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .18rem;
  padding: .58rem .25rem;
  border: 1.5px solid #e2e4f0;
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
  touch-action: manipulation;
  user-select: none;
}
.ai-style-btn:hover { border-color: #667eea; background: #f5f6ff; }
.ai-style-btn.active {
  border-color: #667eea;
  background: #eef0fb;
  box-shadow: 0 2px 8px rgba(102,126,234,.15);
}
.ai-style-icon  { font-size: 1.2rem; }
.ai-style-label { font-size: .72rem; font-weight: 700; color: #444; }
.ai-style-btn.active .ai-style-label { color: #667eea; }

/* ── Toggle checkbox ─────────────────────────────────────────── */
.toggle-label {
  display: flex;
  align-items: center;
  gap: .45rem;
  cursor: pointer;
  font-size: .83rem;
  font-weight: 600;
  color: #555;
  user-select: none;
  touch-action: manipulation;
}
.toggle-label input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: #667eea;
  cursor: pointer;
  flex-shrink: 0;
}
.form-hint {
  font-size: .74rem;
  color: #bbb;
  margin-top: .25rem;
  line-height: 1.5;
}

/* ── Advanced (collapsible) section ─────────────────────────── */
.advanced-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: #f7f8ff;
  border: 1.5px solid #e8eaf6;
  border-radius: 8px;
  padding: .48rem .75rem;
  font-size: .8rem;
  font-weight: 600;
  color: #667eea;
  cursor: pointer;
  margin: .35rem 0 .6rem;
  transition: background .15s, border-color .15s;
  touch-action: manipulation;
  user-select: none;
}
.advanced-toggle:hover { background: #eef0fb; border-color: #667eea; }
.advanced-toggle .arrow {
  display: inline-block;
  transition: transform .25s;
  font-size: 1rem;
  line-height: 1;
}
.advanced-toggle.open .arrow { transform: rotate(90deg); }
.advanced-body { display: none; }
.advanced-body.open { display: block; }

/* ── Generate bar ─────────────────────────────────────────────── */
.generate-bar { margin-top: .75rem; }

/* ── Login modal ─────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-overlay.open { display: flex; }

@keyframes modalIn {
  from { transform: translateY(24px) scale(.96); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ── Single-column card ─── */
.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 22px;
  padding: 2rem 1.75rem 1.5rem;
  box-shadow: 0 28px 72px rgba(0,0,0,.28);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: modalIn .28s cubic-bezier(.34,1.3,.64,1);
}

/* Logo + title block */
.login-card-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
  padding-bottom: .25rem;
}
.login-card-logo {
  height: 44px;
  width: auto;
}
.login-card-title {
  font-size: 1.22rem;
  font-weight: 800;
  color: #667eea;
  letter-spacing: .02em;
}
.login-card-sub {
  font-size: .8rem;
  color: #aaa;
}

/* First-time hint box */
.login-hint-box {
  display: flex;
  gap: .6rem;
  align-items: flex-start;
  background: #eef0ff;
  border-left: 3px solid #667eea;
  border-radius: 0 10px 10px 0;
  padding: .65rem .75rem;
}
.login-hint-icon { font-size: 1.1rem; flex-shrink: 0; line-height: 1.3; }
.login-hint-title { font-size: .82rem; font-weight: 700; color: #555; margin-bottom: .15rem; }
.login-hint-body  { font-size: .78rem; color: #777; line-height: 1.4; }

/* Field label */
.login-field-label {
  font-size: .82rem;
  font-weight: 600;
  color: #555;
  margin-bottom: .3rem;
}

/* modal-step wrapper */
.modal-step { display: flex; flex-direction: column; gap: .65rem; }

.login-input-wrap {
  display: flex;
  align-items: center;
  border: 1.5px solid #e2e4f0;
  border-radius: 10px;
  overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.login-input-wrap:focus-within {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102,126,234,.12);
}
.login-input-prefix {
  padding: 0 .75rem;
  font-size: .88rem;
  color: #999;
  border-right: 1.5px solid #e2e4f0;
  background: #f8f9ff;
  height: 100%;
  display: flex;
  align-items: center;
  white-space: nowrap;
  user-select: none;
}
.login-input-wrap input {
  flex: 1;
  border: none;
  outline: none;
  padding: .72rem .85rem;
  font-size: .98rem;
  background: transparent;
  color: #333;
}
.login-input-wrap input::placeholder { color: #bbb; }

.key-wrap input {
  font-family: "Courier New", monospace;
  letter-spacing: .12em;
  font-size: .95rem;
  text-transform: uppercase;
}

.login-phone-badge {
  background: #f5f6ff;
  border: 1.5px solid #e8eaf6;
  border-radius: 8px;
  padding: .5rem .85rem;
  font-size: .9rem;
  color: #555;
  font-weight: 600;
}

.login-btn {
  width: 100%;
  padding: .78rem;
  font-size: 1rem;
  border-radius: 10px;
  margin-top: .1rem;
}

.login-tip {
  font-size: .75rem;
  color: #bbb;
  text-align: center;
  line-height: 1.5;
}

.login-back-btn {
  background: none;
  border: none;
  color: #aaa;
  font-size: .8rem;
  cursor: pointer;
  text-align: center;
  padding: 0;
  transition: color .15s;
}
.login-back-btn:hover { color: #667eea; }

.login-error {
  background: #fff0f0;
  border: 1px solid #fca5a5;
  color: #c00;
  border-radius: 8px;
  padding: .5rem .75rem;
  font-size: .82rem;
}

.btn-outline {
  background: #fff;
  border: 1.5px solid #dde;
  color: #666;
}
.btn-outline:hover { border-color: #999; color: #333; }

/* ── User status (below generate button) ─────────────────────── */
.user-status {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-size: .8rem;
  color: #888;
  margin-top: .55rem;
  padding: .35rem .5rem;
  background: #f8f9ff;
  border: 1px solid #e8eaf0;
  border-radius: 10px;
}
.user-status-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.quota-bar-wrap {
  display: flex;
  align-items: center;
  gap: .5rem;
}
.quota-bar-track {
  flex: 1;
  height: 6px;
  background: #e8eaf0;
  border-radius: 3px;
  overflow: hidden;
}
.quota-bar-fill {
  height: 100%;
  background: #667eea;
  border-radius: 3px;
  transition: width .4s ease, background .3s;
}
.quota-bar-label {
  font-size: .75rem;
  font-weight: 700;
  white-space: nowrap;
  min-width: 48px;
  text-align: right;
}
.btn-text-link {
  background: none;
  border: none;
  color: #aaa;
  font-size: .78rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  transition: color .15s;
}
.btn-text-link:hover { color: #e53935; }

.quota-empty-hint {
  font-size: .8rem;
  color: #e53935;
  margin-top: .5rem;
  text-align: center;
}

/* ── Login card elements ─────────────────────────────────────── */
.login-trust {
  font-size: .74rem;
  color: #bbb;
  text-align: center;
  line-height: 1.5;
}
.login-buy-hint {
  font-size: .78rem;
  color: #aaa;
  text-align: center;
}

/* Features box */
.login-features-box {
  background: #f8f9ff;
  border-radius: 12px;
  padding: .85rem 1rem;
  border: 1px solid #e8eaf6;
}
.login-features-title {
  font-size: .82rem;
  font-weight: 700;
  color: #667eea;
  margin-bottom: .5rem;
}
.login-features-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.login-features-list li {
  font-size: .78rem;
  color: #555;
  line-height: 1.4;
  padding-left: 1.2rem;
  position: relative;
}
.login-features-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: #667eea;
  font-weight: 700;
}

/* Footer note */
.login-footer-note {
  font-size: .72rem;
  color: #ccc;
  text-align: center;
  line-height: 1.6;
  border-top: 1px solid #f0f0f8;
  padding-top: .75rem;
}
.login-buy-link {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
}
.login-buy-link:hover { text-decoration: underline; }

/* ── Label hints ─────────────────────────────────────────────── */
.label-hint {
  font-size: .72rem;
  font-weight: 400;
  color: #bbb;
  margin-left: .2rem;
}

/* ── Footer ──────────────────────────────────────────────────── */
.footer {
  background: #fff;
  border-top: 1px solid #e8eaf0;
  padding: 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .6rem;
  margin-top: 1.5rem;
}
.footer-logo {
  height: 32px;
  width: auto;
  opacity: .85;
  flex-shrink: 0;
}
.footer-links {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: .78rem;
  color: #bbb;
}
.footer-sep { opacity: .5; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
  .login-card { padding: 1.5rem 1.25rem 1.25rem; border-radius: 16px; }
}

@media (max-width: 768px) {
  .container {
    grid-template-columns: 1fr;
    padding: .75rem;
    gap: .75rem;
  }
  aside { width: 100%; }

  .header { padding: .75rem 1rem; }
  .header .icon { font-size: 1.25rem; }
  .header h1 { font-size: 1.05rem; }
  .header .sub { font-size: .75rem; }

  .panel { padding: 1rem; border-radius: 12px; }
  .panel h2 { font-size: .8rem; margin-bottom: .75rem; }

  /* Larger touch targets on mobile */
  .size-btn { min-height: 40px; font-size: .8rem; }
  .mode-btn { min-height: 58px; padding: .6rem .35rem; }
  .ai-style-btn { min-height: 56px; padding: .5rem .2rem; }
  .ai-style-label { font-size: .68rem; }

  /* Canvas: limit height */
  .canvas-wrap { min-height: 200px; max-height: calc(55vw + 40px); }

  /* Download buttons: stacked full-width on mobile */
  .download-bar > span { display: none; }
  .btn-dl-main { padding: .65rem .5rem; font-size: .82rem; }
  .download-secondary { gap: .32rem; }
  .btn-dl-sec { font-size: .76rem; padding: .38rem .55rem; }

  /* Legend chips slightly smaller on mobile */
  .legend-chip { width: 46px; height: 46px; border-radius: 10px; font-size: .78rem; }

  /* Toast: centered at bottom */
  .toast { left: 1rem; right: 1rem; bottom: 1rem; max-width: none; text-align: center; }

  /* Sticky generate button */
  .generate-bar {
    position: sticky;
    bottom: 0;
    z-index: 30;
    margin: .5rem -1rem -1rem;
    padding: .75rem 1rem;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid #e8eaf0;
    box-shadow: 0 -4px 16px rgba(102,126,234,.12);
  }
  .generate-bar .btn-primary { margin-top: 0; }
}

@media (max-width: 480px) {
  /* Tighter layout on very small phones */
  .ai-style-options { grid-template-columns: repeat(4, 1fr); gap: .28rem; }
  .size-options { gap: .35rem; }
  .mode-options { gap: .35rem; }
}

@media (min-width: 769px) and (max-width: 1100px) {
  .container { grid-template-columns: 300px 1fr; }
}
