:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --border: #e7e9f0;
  --text: #232838;
  --dim: #8a93a6;
  --primary: #f97316;
  --primary-2: #fb923c;
  --primary-dark: #ea580c;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04), 0 10px 30px rgba(17, 24, 39, 0.06);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* 顶栏 */
.topbar {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #ff9a3d 0%, #f43f5e 100%);
  color: #fff;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image: radial-gradient(rgba(255, 255, 255, 0.16) 2.5px, transparent 2.5px);
  background-size: 20px 20px;
}

.topbar-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 16px;
}

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

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 14px;
  font-size: 22px;
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.tagline {
  font-size: 12px;
  opacity: 0.92;
  margin-top: 2px;
}

.version-badge {
  font-size: 11px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.4);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

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

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

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

.card-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 12px;
}

.install-steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--dim);
  line-height: 1.6;
}

.install-steps b {
  color: var(--text);
}

#pwaStatus {
  font-size: 11px;
  max-width: 100%;
  white-space: normal;
}

/* 折叠面板 */
details.card summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
  padding: 2px 0;
}

details.card summary::-webkit-details-marker {
  display: none;
}

details.card summary::after {
  content: "▾";
  margin-left: auto;
  color: var(--dim);
  transition: transform 0.2s;
  font-size: 12px;
}

details.card[open] summary::after {
  transform: rotate(180deg);
}

.card-body {
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.field > label,
.label {
  font-size: 13px;
  color: var(--dim);
}

select,
input[type="number"],
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbfd;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, background 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='%238a93a6' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

select:focus,
input:focus {
  border-color: var(--primary);
  background: #fff;
}

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

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

.hidden {
  display: none !important;
}

/* 分段控件 */
.seg {
  display: flex;
  background: #eef0f5;
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

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

.seg input {
  display: none;
}

.seg span {
  display: block;
  text-align: center;
  padding: 8px 4px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--dim);
  transition: all 0.15s;
}

.seg input:checked + span {
  background: #fff;
  color: var(--primary-dark);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* 勾选 */
.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}

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

.check-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

/* 上传区 */
.dropzone {
  border: 2px dashed #d4d8e2;
  border-radius: 14px;
  background: #fafbfd;
  text-align: center;
  padding: 28px 16px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  margin-top: 12px;
}

.dropzone:hover,
.dropzone.drag {
  border-color: var(--primary);
  background: #fff7f0;
}

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

.dz-main {
  font-size: 15px;
  font-weight: 600;
}

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

.dz-preview {
  max-height: 190px;
  max-width: 100%;
  width: auto;
  object-fit: contain;
  border-radius: 10px;
  display: block;
  margin: 0 auto;
}

.dz-file-name {
  font-size: 12px;
  color: var(--primary-dark);
  margin-top: 8px;
  word-break: break-all;
}

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

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

/* 画布 */
.canvas-wrap {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

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

#patternCanvas.editing {
  cursor: crosshair;
}

.meta {
  font-size: 12px;
  color: var(--dim);
  background: #f1f2f7;
  padding: 4px 10px;
  border-radius: 999px;
}

/* 按钮 */
.btn {
  flex: 1;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.btn.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 16px rgba(249, 115, 22, 0.28);
}

.btn.primary:active {
  transform: scale(0.98);
}

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

.btn.small {
  flex: none;
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.result-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.result-actions .btn,
.bottom-bar .btn {
  flex: 1;
}

/* 底部操作栏（手机端） */
.bottom-bar {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

/* 编辑 */
.edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.edit-color-box {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #eee;
  flex-shrink: 0;
}

.edit-color-name {
  font-size: 13px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pick-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(26px, 1fr));
  gap: 5px;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #fafbfd;
  margin-top: 8px;
}

.pick-swatch {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  cursor: pointer;
  padding: 0;
}

.pick-swatch.selected {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.note {
  font-size: 12px;
  color: var(--dim);
  line-height: 1.5;
}

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

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

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

.legend-item:hover {
  border-color: var(--primary);
}

.swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.legend-code {
  font-weight: 700;
  color: var(--primary-dark);
}

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

.legend-count {
  margin-left: auto;
  font-weight: 600;
}

/* 教程 */
.tutorial-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--dim);
  margin-bottom: 12px;
}

.tutorial-meta span {
  background: #f1f2f7;
  padding: 4px 10px;
  border-radius: 999px;
}

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

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

.steps li::before {
  content: counter(step);
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  margin-top: 2px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.warning {
  margin-top: 12px;
  font-size: 13px;
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 9px 12px;
}

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

/* 桌面端 */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 390px minmax(0, 1fr);
    align-items: start;
    padding: 20px 24px 40px;
  }

  .topbar-inner {
    padding: 20px 24px;
  }

  .bottom-bar {
    display: none !important;
  }
}

/* 手机端 */
@media (max-width: 899px) {
  .result-actions {
    display: none;
  }

  .bottom-bar {
    display: flex;
  }
}

/* 打印 */
@media print {
  .topbar,
  .side,
  .bottom-bar,
  .result-actions {
    display: none !important;
  }

  body {
    background: #fff;
  }

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

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

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