/* ============================================
   拼豆工坊 · 移动端优先设计
   暖纸底色 / 墨色文字 / 珊瑚红主色 / 豆子质感
   ============================================ */

:root {
  --paper: #f5eee0;
  --card: #fffdf6;
  --ink: #2b2118;
  --ink-soft: #77695a;
  --line: #e6dac4;
  --coral: #ff5a3c;
  --coral-deep: #e0431f;
  --coral-soft: #ffe3d8;
  --teal: #0e9c9c;
  --teal-soft: #d8f0ec;
  --gold: #f2b33d;
  --gold-soft: #fbeecb;
  --radius-lg: 22px;
  --radius-md: 14px;
  --shadow-card: 0 1px 2px rgba(43, 33, 24, 0.04), 0 14px 34px rgba(43, 33, 24, 0.09);
  --font-display: "Yuanti SC", "YouYuan", "幼圆", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-body: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei", sans-serif;
}

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

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.55;
  min-height: 100vh;
  background-color: var(--paper);
  background-image: radial-gradient(rgba(43, 33, 24, 0.05) 1.1px, transparent 1.5px);
  background-size: 18px 18px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
}

/* 纸张颗粒质感（全屏固定，不影响交互） */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 99;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='0.045'/%3E%3C/svg%3E");
}

/* ---------- 顶栏：墨色拼豆板 ---------- */
.topbar {
  position: relative;
  overflow: hidden;
  background: var(--ink);
  color: var(--card);
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 253, 246, 0.13) 2px, transparent 2.6px);
  background-size: 22px 22px;
}

.topbar-inner {
  position: relative;
  display: flex;
  align-items: center;
  max-width: 640px;
  margin: 0 auto;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
}

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

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 15px;
  background: var(--coral);
  font-size: 21px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.18), 0 3px 0 rgba(0, 0, 0, 0.28);
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.tagline {
  font-size: 11px;
  opacity: 0.82;
  margin-top: 1px;
  letter-spacing: 0.3px;
}

/* ---------- 布局 ---------- */
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(30px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.view.hidden {
  display: none;
}

/* 页面切换动画 */
@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

#setupView:not(.hidden),
#resultView:not(.hidden) {
  animation: viewIn 0.35s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.view .card {
  animation: viewIn 0.4s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.view .card:nth-child(2) {
  animation-delay: 0.06s;
}

.view .card:nth-child(3) {
  animation-delay: 0.12s;
}

.view .card:nth-child(4) {
  animation-delay: 0.18s;
}

/* ---------- 卡片：拼豆托盘 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 18px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 14px;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

/* ---------- 字段 ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > label,
.label {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 600;
}

select,
input[type="number"],
input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  background: #fff;
  font-size: 16px; /* 防 iPhone 聚焦自动缩放 */
  font-family: inherit;
  color: var(--ink);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

select {
  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 fill='%2377695a' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

select:focus,
input:focus {
  border-color: var(--coral);
  box-shadow: 0 0 0 3px var(--coral-soft);
}

.custom-size {
  display: flex;
  align-items: center;
  gap: 8px;
}

.custom-size span {
  color: var(--ink-soft);
}

.hidden {
  display: none !important;
}

/* ---------- 分段控件：墨色轨道 ---------- */
.seg {
  display: flex;
  background: var(--ink);
  border-radius: 16px;
  padding: 5px;
  gap: 5px;
}

.seg label {
  flex: 1;
  cursor: pointer;
}

.seg input {
  display: none;
}

.seg span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 4px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 253, 246, 0.72);
  transition: all 0.18s;
}

.seg input:checked + span {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.22);
}

/* ---------- 勾选 ---------- */
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
  min-height: 36px;
}

.check input {
  accent-color: var(--coral);
  width: 18px;
  height: 18px;
}

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
}

/* ---------- 上传区 ---------- */
.dropzone {
  border: 2px dashed #d9cbb0;
  border-radius: 18px;
  background: #fffcf2;
  text-align: center;
  padding: 30px 16px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
}

.dropzone:hover,
.dropzone.drag {
  border-color: var(--coral);
  background: var(--coral-soft);
  transform: scale(1.01);
}

.dz-icon {
  font-size: 34px;
  line-height: 1;
  margin-bottom: 10px;
}

.dz-main {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 700;
}

.dz-hint {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 6px;
}

.dz-preview {
  max-height: 190px;
  max-width: 100%;
  width: auto;
  object-fit: contain;
  border-radius: 14px;
  display: block;
  margin: 0 auto;
  box-shadow: 0 4px 16px rgba(43, 33, 24, 0.12);
}

.dz-file-name {
  font-size: 12px;
  color: var(--coral-deep);
  margin-top: 10px;
  word-break: break-all;
}

.dropzone.has-image {
  padding: 12px;
  border-style: solid;
  border-color: var(--line);
  background: var(--card);
}

.dropzone.has-image .dz-inner {
  display: none;
}

/* ---------- 按钮：豆子质感 ---------- */
.btn {
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 16px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s, background 0.15s;
  touch-action: manipulation;
}

.btn.primary {
  background: linear-gradient(180deg, #ff7a5c, var(--coral));
  border-color: var(--coral-deep);
  color: #fff;
  box-shadow: 0 4px 0 var(--coral-deep), 0 10px 20px rgba(224, 67, 31, 0.22);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.08);
}

.btn:active {
  transform: translateY(2px) scale(0.99);
}

.btn.primary:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--coral-deep);
}

.btn:not(.primary):hover {
  border-color: var(--coral);
  color: var(--coral-deep);
}

.btn-lg {
  width: 100%;
  min-height: 52px;
  font-size: 17px;
  border-radius: 18px;
}

.btn.small {
  min-height: 42px;
  flex: none;
  padding: 9px 16px;
  font-size: 14px;
  border-radius: 13px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
  transform: none !important;
}

/* ---------- 结果页顶栏 ---------- */
.result-topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  background: rgba(245, 238, 224, 0.88);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  font-size: 19px;
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s;
}

.icon-btn:active {
  transform: scale(0.92);
}

.result-title {
  flex: 1;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
}

/* ---------- 画布：拼豆板 ---------- */
.canvas-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.canvas-wrap {
  background: #fff;
  border: 2px solid var(--line);
  border-radius: 18px;
  padding: 10px;
  display: flex;
  justify-content: center;
  overflow: hidden;
  box-shadow: inset 0 2px 8px rgba(43, 33, 24, 0.07);
}

#patternCanvas {
  max-width: 100%;
  height: auto;
  background: #fff;
  border-radius: 8px;
}

#patternCanvas.editing {
  cursor: crosshair;
  touch-action: none;
}

.meta {
  font-size: 12px;
  color: var(--ink-soft);
  background: #f4ead7;
  padding: 6px 12px;
  border-radius: 999px;
  text-align: center;
  align-self: center;
}

.preview-actions {
  display: flex;
  gap: 10px;
}

.preview-actions .btn {
  flex: 1;
}

/* ---------- 编辑工具 ---------- */
.edit-tools-head {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.edit-tools-head input {
  flex: 1;
}

.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
  gap: 7px;
  border: 1.5px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: #fffcf2;
}

.pick-h {
  display: flex;
  overflow-x: auto;
  flex-wrap: nowrap;
  gap: 9px;
  scrollbar-width: none;
}

.pick-h::-webkit-scrollbar {
  display: none;
}

.pick-swatch {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 1px solid rgba(0, 0, 0, 0.16);
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: transform 0.12s, box-shadow 0.12s;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12), inset 0 2px 2px rgba(255, 255, 255, 0.35);
}

.pick-swatch:active {
  transform: scale(0.9);
}

.pick-swatch.selected {
  outline: 3px solid var(--coral);
  outline-offset: 2px;
  transform: scale(1.08);
  box-shadow: 0 4px 10px rgba(224, 67, 31, 0.28);
}

.note {
  font-size: 12px;
  color: var(--ink-soft);
  line-height: 1.55;
}

.note-inline {
  font-size: 12px;
  margin-top: 10px;
}

/* ---------- 色号清单 ---------- */
.legend {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 9px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fffcf2;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s;
}

.legend-item:active {
  transform: scale(0.97);
  border-color: var(--coral);
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.14);
  flex-shrink: 0;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.1);
}

.legend-code {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  color: var(--card);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.legend-name {
  color: var(--ink-soft);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-count {
  margin-left: auto;
  font-weight: 700;
  color: var(--coral-deep);
  white-space: nowrap;
}

/* ---------- 教程 ---------- */
.tutorial-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 14px;
}

.tutorial-meta span {
  background: var(--teal-soft);
  color: var(--teal);
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 600;
}

.steps {
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.steps li {
  display: flex;
  gap: 11px;
  font-size: 14px;
  line-height: 1.65;
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--coral);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.warning {
  margin-top: 14px;
  font-size: 13px;
  color: #8a5a00;
  background: var(--gold-soft);
  border: 1px solid #f0d492;
  border-radius: 14px;
  padding: 10px 14px;
}

.dim {
  color: var(--ink-soft);
}

/* ---------- 打印 ---------- */
@media print {
  .topbar,
  .view.hidden,
  .result-topbar,
  #editTools,
  .preview-actions {
    display: none !important;
  }

  body {
    background: #fff;
    background-image: none;
  }

  body::after {
    display: none;
  }

  .app {
    max-width: none;
    padding: 0;
  }

  .card {
    border: none;
    box-shadow: none;
    padding: 0;
    margin-bottom: 12px;
    animation: none !important;
  }

  .canvas-wrap {
    border: none;
    padding: 0;
    box-shadow: none;
  }
}
