/* ==========================================================================
   拼豆图纸生成器 —— 样式
   视觉方向：暖调纸感（牛皮纸/工作台），配合拼豆的方格像素感
   ========================================================================== */

:root {
  --bg:            #F5F2EC;
  --surface:       #FFFFFF;
  --surface-2:     #FAF8F4;
  --surface-3:     #F1EDE5;
  --ink:           #221F1B;
  --ink-2:         #5C554C;
  --muted:         #8C8378;
  --border:        #E5DED3;
  --border-strong: #D3C9B9;
  --accent:        #D9542F;
  --accent-dark:   #B8431F;
  --accent-soft:   #FCEFE9;
  --teal:          #1F7A72;
  --teal-soft:     #E6F2F0;

  --radius:   12px;
  --radius-s: 8px;
  --shadow:   0 1px 2px rgba(40, 30, 20, .05), 0 8px 24px -12px rgba(40, 30, 20, .16);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

/* 作者样式里的 display 会盖掉浏览器默认的 [hidden]{display:none}，
 * 所以这里显式兜底，避免隐藏元素（判白滑块 / 收款码图片）又冒出来。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

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

/* ============================== 顶栏 ============================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(245, 242, 236, .88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.logo {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 9px;
  background: repeating-conic-gradient(var(--accent) 0% 25%, #F6CFC2 0% 50%) 50% / 16px 16px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
}

.brand-text h1 { font-size: 16px; line-height: 1.25; }
.brand-text p { margin: 0; font-size: 12px; color: var(--muted); }

.topbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ============================== 按钮 ============================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .14s, border-color .14s, transform .08s, opacity .14s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .42; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn.ghost { background: transparent; border-color: var(--border-strong); }
.btn.ghost:hover { background: var(--surface); }

.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }

/* ============================== 布局 ============================== */

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
  max-width: 1840px;
  margin: 0 auto;
  padding: 16px 20px 28px;
}

.col { min-width: 0; display: flex; flex-direction: column; gap: 14px; }

.col-center {
  position: sticky;
  top: 72px;
}

/* ============================== 卡片 ============================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 10px;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.card-title-row .card-title { margin-bottom: 0; }

.as-summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 0;
  padding: 2px 0;
}
.as-summary::-webkit-details-marker { display: none; }
.as-summary::before {
  content: "▸";
  color: var(--muted);
  transition: transform .15s;
  display: inline-block;
}
details[open] > .as-summary::before { transform: rotate(90deg); }
details[open] > .as-summary { margin-bottom: 10px; }

.badge {
  flex: none;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 700;
}

/* ============================== 表单 ============================== */

.field { display: block; margin-bottom: 12px; }
.field.grow { flex: 1 1 auto; margin-bottom: 0; }

.field-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 5px;
}
.field-label b { font-family: var(--mono); font-size: 13px; color: var(--accent-dark); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
  margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

input[type="number"], .select {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 13px;
}
input[type="number"]:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  margin: 9px 0;
  cursor: pointer;
  user-select: none;
}
.check.small { font-size: 12px; margin: 0; }
.check input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: none;
}

.row { display: flex; align-items: center; }
.row.gap-xs { gap: 6px; }
.row.gap-sm { gap: 8px; flex-wrap: wrap; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }
.mt-lg { margin-top: 18px; }

.hint { font-size: 11.5px; line-height: 1.55; color: var(--muted); margin: 6px 0 0; }
.hint.center { text-align: center; }
.hint b { color: var(--ink-2); }

.file-meta {
  font-size: 11.5px;
  color: var(--muted);
  margin: 8px 0 0;
  word-break: break-all;
}

/* ============================== 上传区 ============================== */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
  text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  margin-bottom: 4px;
  background: repeating-conic-gradient(var(--accent) 0% 25%, #FBDFD5 0% 50%) 50% / 19px 19px;
  opacity: .85;
}
.dropzone-main { margin: 0; font-size: 13px; font-weight: 600; }
.dropzone-sub { margin: 0; font-size: 11.5px; color: var(--muted); }

/* ============================== 工具按钮 ============================== */

.toolbar-tools {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.tool {
  padding: 8px 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .14s, border-color .14s, color .14s;
}
.tool:hover { background: var(--surface-3); }
.tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.current-color {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface-2);
}
.current-color .swatch {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, .14);
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .5);
}
.current-color-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.current-color-text b { font-family: var(--mono); font-size: 13px; }
.current-color-text span { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ============================== 画布区 ============================== */

.canvas-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: none;
}
.zoom-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  min-width: 44px;
  text-align: center;
}
.zoom-hint { font-size: 11px; color: var(--muted); }

.canvas-scroll {
  position: relative;
  overflow: auto;
  max-height: calc(100vh - 232px);
  min-height: 320px;
  padding: 14px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.022) 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(rgba(0,0,0,.022) 1px, transparent 1px) 0 0 / 22px 22px,
    var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
}

.canvas-stack { position: relative; width: max-content; }
#gridCanvas { display: block; border-radius: 3px; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

#overlayCanvas {
  position: absolute;
  top: 0; left: 0;
  cursor: crosshair;
  touch-action: none;
}

.hover-tip {
  position: absolute;
  z-index: 5;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(28, 24, 20, .92);
  color: #fff;
  font-size: 11px;
  font-family: var(--mono);
  white-space: nowrap;
  pointer-events: none;
  transform: translate(10px, 10px);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}
.empty-state[hidden] { display: none; }
.empty-inner { text-align: center; max-width: 340px; padding: 24px; }
.empty-inner h3 { font-size: 16px; margin-bottom: 6px; }
.empty-inner p { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.7; }
.empty-art {
  width: 88px; height: 88px;
  margin: 0 auto 16px;
  border-radius: 18px;
  background: repeating-conic-gradient(var(--accent) 0% 25%, #FBE0D7 0% 50%) 50% / 30px 30px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .05);
  opacity: .9;
}

.stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 12px;
  color: var(--muted);
}
.stats-bar b { font-family: var(--mono); font-size: 13px; color: var(--ink); margin-left: 4px; }

/* 画布上方的 toolbar 与下方 stats 合并圆角处理 */
.canvas-toolbar + .canvas-scroll + .stats-bar { margin-top: -1px; }

/* ============================== 色号清单表 ============================== */

.counts-wrap {
  max-height: 46vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  background: var(--surface);
}

.counts-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
}
.counts-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-3);
  padding: 7px 8px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.counts-table th.num, .counts-table td.num { text-align: right; font-family: var(--mono); }
.counts-table th.col-sw { width: 34px; }

.counts-table tbody tr { cursor: pointer; }
.counts-table tbody tr:hover { background: var(--accent-soft); }
.counts-table tbody tr.selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.counts-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.counts-table tbody tr:last-child td { border-bottom: none; }

.counts-table .sw {
  width: 22px; height: 22px;
  border-radius: 5px;
  border: 1px solid rgba(0, 0, 0, .16);
  display: block;
}
.counts-table .code { font-family: var(--mono); font-weight: 700; }
.counts-table .nm { color: var(--ink-2); max-width: 78px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.counts-table .cnt { font-weight: 700; }
.counts-table .pct { color: var(--muted); font-size: 11px; }
.counts-table .empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 26px 8px;
  cursor: default;
}

/* ============================== 色卡管理 ============================== */

.palette-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.palette-actions .select { flex: 1 1 140px; font-family: var(--sans); font-size: 12px; padding: 5px 8px; }

.palette-list {
  max-height: 300px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
}
.palette-row {
  display: grid;
  grid-template-columns: 30px 54px 1fr 24px;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.palette-row:last-child { border-bottom: none; }
.palette-row input[type="color"] {
  width: 26px; height: 24px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: none;
  cursor: pointer;
}
.palette-row input[type="text"] {
  width: 100%;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  font-size: 12px;
  min-width: 0;
}
.palette-row input[type="text"].p-code { font-family: var(--mono); font-weight: 700; }
.palette-row input[type="text"]:hover { background: var(--surface-3); }
.palette-row input[type="text"]:focus { background: #fff; border-color: var(--border-strong); outline: none; }
.palette-row .p-del {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 2px;
  border-radius: 4px;
}
.palette-row .p-del:hover { color: var(--accent); background: var(--accent-soft); }

/* ============================== 打赏区 ============================== */

.donate {
  margin: 8px 20px 0;
  border-top: 1px solid var(--border);
  background: linear-gradient(180deg, transparent, var(--surface) 40%);
  border-radius: var(--radius);
}
.donate-inner {
  max-width: 1020px;
  margin: 0 auto;
  padding: 34px 20px 30px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 312px;
  gap: 34px;
  align-items: center;
}
.donate-copy h2 { font-size: 20px; margin-bottom: 10px; }
.donate-copy p { margin: 0 0 14px; color: var(--ink-2); font-size: 13.5px; line-height: 1.85; }
.donate-copy p b { color: var(--ink); }
.donate-points { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.donate-points li {
  position: relative;
  padding-left: 20px;
  font-size: 12.5px;
  color: var(--muted);
}
.donate-points li::before {
  content: "";
  position: absolute;
  left: 3px; top: 8px;
  width: 6px; height: 6px;
  border-radius: 2px;
  background: var(--teal);
  opacity: .65;
}

.donate-qr { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.qr-slot {
  position: relative;
  width: 280px; height: 280px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.qr-slot:hover { border-color: var(--accent); background: var(--accent-soft); }
/* 站点收款码是实图，去掉虚线框和手型光标，让它看起来就是一张图 */
.qr-slot.has-image,
.qr-slot.has-image:hover {
  border-style: solid;
  border-color: var(--border);
  background: #fff;
  cursor: default;
}
.qr-slot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.qr-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  padding: 10px;
}
.qr-placeholder small { font-size: 10.5px; opacity: .8; }
.qr-plus { font-size: 26px; line-height: 1; color: var(--border-strong); }
.qr-actions { display: flex; gap: 6px; }

.qr-note {
  max-width: 250px;
  margin: 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
  text-align: center;
}

/* ============================== 页脚 / 提示条 ============================== */

.footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  justify-content: space-between;
  padding: 18px 24px 30px;
  font-size: 11.5px;
  color: var(--muted);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 90;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(28, 24, 20, .94);
  color: #fff;
  font-size: 12.5px;
  box-shadow: 0 8px 26px -8px rgba(0, 0, 0, .5);
  animation: toast-in .18s ease-out;
}
.toast[hidden] { display: none; }
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ============================== 响应式 ============================== */

@media (max-width: 1440px) {
  .layout { grid-template-columns: 286px minmax(0, 1fr) 310px; }
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: 286px minmax(0, 1fr); }
  .col-right { grid-column: 1 / -1; flex-direction: row; align-items: start; }
  .col-right > .card { flex: 1 1 340px; }
  .col-center { position: static; }
  .canvas-scroll { max-height: 70vh; }
}

@media (max-width: 860px) {
  .topbar { padding: 10px 14px; }
  .topbar-actions { width: 100%; }
  .topbar-actions .btn { flex: 1 1 auto; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 14px 24px; }
  .col-right { flex-direction: column; }
  .canvas-scroll { max-height: 62vh; padding: 10px; }
  .donate { margin: 8px 14px 0; }
  .donate-inner { grid-template-columns: minmax(0, 1fr); gap: 24px; text-align: center; }
  .donate-points { align-items: center; }
  .donate-points li { text-align: left; }
  .footer { flex-direction: column; padding: 16px 16px 26px; }
}
