/* Texture Desk —— 浅色工作台
   参考 19dlab 的信息层级：浅灰桌面 + 白色浮起卡片 + 极薄描边 + 小字号 */

:root {
  --bg: #f1f1f3;          /* 桌面 */
  --card: #ffffff;        /* 卡片 */
  --ink: #18181b;         /* 主文字 */
  --muted: #71717a;       /* 次要文字 */
  --line: rgba(24, 24, 27, 0.08);   /* 卡片上的细线 */
  --line-2: #e4e4e7;     /* 控件描边 */
  --fill: #f4f4f5;       /* 次级按钮/悬停底 */
  --fill-2: #ebebef;     /* 悬停加深 */
  --accent: #2357ff;     /* 强调蓝 */
  --radius-card: 16px;
  --radius-ctl: 8px;
  --radius-sm: 6px;
  --shadow-card: 0 1px 2px rgba(16, 17, 20, 0.04), 0 8px 24px rgba(16, 17, 20, 0.05);
  --f-11: 12px;
  --f-12: 12px;
  --f-13: 13px;
  --f-15: 15px;
}

* { box-sizing: border-box; }
/* 布局类元素自带 display，会盖掉 hidden，统一兜住 */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: var(--f-13)/1.5 Inter, -apple-system, "SF Pro Text", "PingFang SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* 桌面布局：左参数、中画布、右颜色与导出 */
.layout {
  height: 100%;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 264px;
  gap: 16px;
  padding: 16px;
}

.card {
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: contain;
}

/* 左栏整块滚，右栏只滚参数区，导出永远贴底 */
.side { overflow-y: auto; }
.side.right { overflow: hidden; }
.scroll-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 20px;
  margin: -2px -6px 0 0;
  padding: 2px 6px 0 0;
}

.side { padding: 16px 16px 18px; gap: 14px; align-self: stretch; max-height: calc(100vh - 32px); }
.side.right { gap: 16px; }
.side::-webkit-scrollbar { width: 0; height: 0; }
.side { scrollbar-width: none; }
.side.right .section:last-of-type { margin-top: 8px; }

.side-head { display: flex; flex-direction: column; gap: 2px; }
.side-foot { margin-top: auto; padding-top: 12px; font-size: var(--f-11); color: #71717a; }
.title { margin: 0; font-size: var(--f-15); font-weight: 600; letter-spacing: -0.01em; }
.subtitle { font-size: var(--f-11); color: var(--muted); }

.section { display: flex; flex-direction: column; gap: 9px; }
.section-label {
  font-size: var(--f-11);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.03em;
}

/* 生成器：分段控件 */
.gens {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 2px;
  background: var(--bg);
  border-radius: var(--radius-ctl);
}
.gen {
  height: 28px;
  padding: 0 2px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #52525b;
  font-size: var(--f-12);
  font-weight: 500;
  cursor: pointer;
  transition: background 160ms ease-out, color 160ms ease-out;
}
.gen:hover { color: var(--ink); }
.gen[aria-selected="true"] {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 17, 20, 0.1);
}
.gen small { display: none; }

/* 参数 */
.params { display: flex; flex-direction: column; gap: 6px; }
.param { display: flex; flex-direction: column; gap: 2px; }
.param-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: var(--f-12);
  line-height: 1.25;
  color: var(--muted);
}
.param-head b {
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.param-head .num-group { display: flex; align-items: baseline; gap: 6px; }
.param-reset {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--fill);
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 140ms ease-out, background 140ms ease-out;
}
.param:hover .param-reset, .param-reset:focus-visible { opacity: 1; }
.param-reset:hover { background: var(--fill-2); color: var(--ink); }

/* 滑杆 */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: var(--line-2);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5.5px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
  box-shadow: 0 1px 2px rgba(16, 17, 20, 0.25);
  cursor: pointer;
  transition: transform 160ms ease-out;
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.1); }
input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
  border-radius: 2px;
}

/* 下拉 */
select {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  background: var(--fill);
  color: var(--ink);
  border: 0.5px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--f-12);
  cursor: pointer;
}
select:hover { background: var(--fill-2); }
select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 按钮 */
button {
  font: inherit;
  font-size: var(--f-12);
  font-weight: 500;
  color: var(--ink);
  background: var(--fill);
  border: 0.5px solid transparent;
  border-radius: var(--radius-sm);
  height: 30px;
  padding: 0 11px;
  cursor: pointer;
  transition: background 160ms ease-out;
}
button:hover { background: var(--fill-2); }
button.primary { background: var(--ink); color: #fff; }
button.primary:hover { background: #2c2c31; }
button.wide { width: 100%; height: 34px; }
button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:disabled:hover { background: var(--fill); }

/* 颜色 */
.colors { display: flex; gap: 14px; }
.swatch {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--f-12);
  color: var(--muted);
  cursor: pointer;
}
/* 色块：自绘按钮，点开色值浮层；原生取色器缩到不可见，只作取色通道 */
.swatch-dot {
  width: 30px;
  height: 24px;
  padding: 0;
  border: 0.5px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--fill);
  cursor: pointer;
  overflow: hidden;
  display: block;
}
.swatch-dot i { display: block; width: 100%; height: 100%; background: #fff; }
.swatch-dot:hover { border-color: #c9c9cf; }
.swatch-native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  padding: 0;
  border: 0;
  pointer-events: none;
}
.check {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: var(--f-12);
  color: var(--muted);
  cursor: pointer;
}
.check input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--ink);
  cursor: pointer;
}
.slot-colors { display: flex; flex-direction: column; gap: 7px; margin-top: 6px; }
.slot-color-row { display: flex; align-items: center; gap: 8px; }
.slot-color-name { font-size: var(--f-12); color: var(--muted); flex: 1; }
.slot-color-head { padding-bottom: 1px; margin-bottom: 4px; }
.sw-tag { width: 42px; }
.sw-w {
  width: 42px;
  height: 24px;
  flex: none;
  padding: 0 6px;
  border: 0.5px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: #fff;
  font: inherit;
  font-size: var(--f-12);
  color: var(--ink);
  text-align: right;
}
.sw-w::-webkit-inner-spin-button,
.sw-w::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.slot-color-tag {
  width: 30px;
  flex: none;
  text-align: center;
  font-size: var(--f-11);
  color: var(--muted);
}

.swatch-wrap { position: relative; display: inline-flex; }
/* 不填色 / 不描边：色块显示斜线 */
.is-none .swatch-dot i {
  background: repeating-linear-gradient(135deg, #d4d4d8 0 2px, transparent 2px 5px) !important;
  opacity: 1;
}

/* 上色方式：分段 */
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 2px;
  background: var(--bg);
  border-radius: var(--radius-ctl);
}
.seg button {
  height: 26px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--f-12);
  font-weight: 500;
}
.seg button[aria-selected="true"] {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 17, 20, 0.1);
}

/* 数值输入 */
.num-field { display: flex; align-items: center; gap: 4px; }
.num-field input {
  width: 62px;
  height: 28px;
  padding: 0 8px;
  border: 0.5px solid var(--line-2);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--f-12);
  text-align: right;
  color: var(--ink);
  background: var(--card);
}
.num-field i { font-style: normal; font-size: var(--f-11); color: var(--muted); }
.field input[type="color"] {
  width: 30px;
  height: 24px;
  padding: 0;
  border: 0.5px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}
.sub-title { font-size: var(--f-12); color: var(--muted); }
/* 解构这一块的小标题，和右栏其它分区标签同一套 */
.section-title {
  margin-top: 6px;
  font-size: var(--f-11);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.03em;
}
.palettes { display: flex; flex-wrap: wrap; gap: 5px; }
.pal {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 26px;
  padding: 0 4px;
  border-radius: var(--radius-sm);
  background: var(--fill);
  border: 0.5px solid transparent;
  cursor: pointer;
}
.pal:hover { background: var(--fill-2); }
.pal i {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  display: block;
  border: 0.5px solid rgba(0, 0, 0, 0.12);
}
/* 没有描边的方案，第三个色块画一条斜线 */
.pal i.is-none {
  background: repeating-linear-gradient(135deg, #d4d4d8 0 2px, transparent 2px 4px);
}

/* 导出区 */
.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: var(--f-12);
  color: var(--muted);
}
.field select { width: 112px; }

/* 画布区 */
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 12px;
}
.stage-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 18px;
  flex: none;
  font-size: var(--f-12);
}
.canvas-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  padding: 4px 0 8px;
}
#preview {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-card);
  box-shadow: 0 1px 2px rgba(16, 17, 20, 0.06), 0 14px 40px rgba(16, 17, 20, 0.1);
  background: #f4f1ea;
}
.stage.drop-active .canvas-wrap { outline: 1px dashed var(--accent); outline-offset: -10px; border-radius: var(--radius-card); }

/* 预设 */
.presets {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  min-height: 52px;
  overflow-x: auto;
  scrollbar-width: none;
}
.presets::-webkit-scrollbar { display: none; }
.presets-label { font-size: var(--f-11); color: var(--muted); flex: none; }
.preset-list { display: flex; gap: 6px; flex-wrap: nowrap; }
.preset {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 10px 0 6px;
  font-size: var(--f-12);
  border-radius: 999px;
  background: var(--fill);
  border: 0.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.preset:hover { background: var(--fill-2); }
.preset i {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: block;
  border: 0.5px solid rgba(0, 0, 0, 0.12);
}

/* 图像上传 */
.drop { display: flex; align-items: center; gap: 8px; }
.drop-hint { font-size: var(--f-12); color: var(--muted); }
.thumb { display: flex; align-items: center; gap: 10px; }
.thumb img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--line-2);
  background: #fff;
}
.thumb-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.thumb-meta b {
  font-size: var(--f-12);
  font-weight: 500;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thumb-meta button { height: 24px; padding: 0 8px; align-self: flex-start; }

/* 开关 */
.switch { flex-direction: row; align-items: center; justify-content: space-between; font-size: var(--f-12); color: var(--muted); }
.switch input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: var(--line-2);
  border: 0;
  position: relative;
  cursor: pointer;
  transition: background 200ms ease-out;
}
.switch input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 17, 20, 0.2);
  transition: transform 200ms ease-out;
}
.switch input[type="checkbox"]:checked { background: var(--ink); }
.switch input[type="checkbox"]:checked::after { transform: translateX(14px); }

/* 图形槽 */
.slots { display: flex; flex-direction: column; gap: 7px; }
.slot { display: flex; align-items: center; gap: 6px; font-size: var(--f-12); }
.slot-grip {
  width: 12px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 12px;
  line-height: 1;
  color: #a1a1aa;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.slot-grip:hover { color: var(--ink); }
.slot-grip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.slot.is-dragging { opacity: 0.55; }
.slot-name { color: var(--muted); width: 14px; flex: none; font-size: var(--f-12); white-space: nowrap; text-align: center; }
.slot-file {
  color: var(--ink);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.slot-btn, .slot-reset { height: 24px; padding: 0 7px; font-size: var(--f-12); flex: none; }
.slot-angle {
  width: 56px;
  height: 24px;
  padding: 0 2px 0 6px;
  font-size: var(--f-12);
  border-radius: var(--radius-sm);
  flex: none;
}
.slot-angle:hover { background: var(--fill-2); }
.slot-thumb {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 5px;
  background: #fff;
  object-fit: contain;
  border: 0.5px solid var(--line-2);
}
.slot-thumb-none { background: transparent; border-style: dashed; }
.slot-thumb-svg { background: #fff; padding: 2px; }
.slots-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

/* 组合库 */
.comps {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, auto);
  grid-auto-columns: 56px;
  gap: 4px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.comps::-webkit-scrollbar { display: none; }
.comp {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  gap: 2px;
  height: auto;
  padding: 4px 2px 4px;
  border-radius: var(--radius-ctl);
  border: 0.5px solid transparent;
  background: transparent;
  cursor: pointer;
}
.comp:hover { background: var(--fill); }
.comp.on { border-color: var(--ink); background: var(--fill); }
.comp svg { border-radius: 5px; display: block; }
.comp span {
  max-width: 100%;
  font-size: var(--f-11);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.comp.on span { color: var(--ink); }

/* 解构 */
.ref {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 10px;
  border-top: 0.5px solid var(--line);
}
.ref-actions { display: flex; align-items: center; gap: 8px; }
.ref-hint {
  font-size: var(--f-12);
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ref-box {
  position: relative;
  line-height: 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 0.5px solid var(--line-2);
}
.ref-box img { width: 100%; display: block; cursor: crosshair; }
.ref-marker {
  position: absolute;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 0 9999px rgba(24, 24, 27, 0.4);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.ref-slots { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; }
.ref-take { height: 26px; padding: 0 4px; font-size: var(--f-11); }
.param.is-off { opacity: 0.45; }

/* 窗口变窄：先收卡片，再落成上下叠放 */
@media (max-width: 1260px) {
  .layout { grid-template-columns: 232px minmax(0, 1fr) 232px; gap: 12px; padding: 12px; }
  .side { padding: 14px 14px 16px; }
}
@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(260px, 1fr) auto;
    overflow-y: auto;
    height: auto;
    min-height: 100%;
    padding: 12px;
  }
  .side { overflow: visible; max-height: none; }
  /* 窄屏先看画布：画布置顶，参数与颜色排到下面 */
  .stage { order: -1; height: 64vh; }
  .canvas-wrap { padding: 8px 0; min-height: 0; }
  #preview { max-height: 100%; }
  body { overflow-y: auto; }
}

/* 色值浮层 */
.color-pop {
  position: fixed;
  z-index: 40;
  width: 188px;
  padding: 10px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 2px 6px rgba(16, 17, 20, 0.08), 0 12px 32px rgba(16, 17, 20, 0.14);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pop-row { display: flex; align-items: center; gap: 6px; }
.pop-hex {
  flex: 1;
  height: 28px;
  padding: 0 8px;
  border: 0.5px solid var(--line-2);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: var(--f-12);
  color: var(--ink);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.pop-native {
  width: 28px;
  height: 28px;
  flex: none;
  padding: 0;
  border: 0.5px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
}
.pop-native::-webkit-color-swatch-wrapper { padding: 0; }
.pop-native::-webkit-color-swatch { border: none; border-radius: 5px; }
.pop-none {
  height: 26px;
  border: 0.5px solid var(--line-2);
  border-radius: var(--radius-sm);
  background: var(--fill);
  color: var(--ink);
  font: inherit;
  font-size: var(--f-12);
  cursor: pointer;
}
.pop-none:hover { background: var(--fill-2); }

/* 参数区可滚动时，底边渐隐提示 */
.scroll-body.is-scroll {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 20px), rgba(0, 0, 0, 0.15));
  mask-image: linear-gradient(to bottom, #000 calc(100% - 20px), rgba(0, 0, 0, 0.15));
}

/* 画布读数与导出反馈 */
.export-note {
  margin: 0;
  min-height: 16px;
  font-size: var(--f-12);
  color: var(--muted);
}
.export-note.is-ok { color: #15803d; }

/* 预设选中态 */
.preset[aria-pressed="true"] {
  background: var(--card);
  box-shadow: inset 0 0 0 0.5px var(--ink);
}

/* 组合库可横向滚动时的边缘提示 */
.comps {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 22px), rgba(0, 0, 0, 0.15));
  mask-image: linear-gradient(to right, #000 calc(100% - 22px), rgba(0, 0, 0, 0.15));
}

/* 移动端：输入字号提到 16px，避免 iOS 聚焦时自动放大 */
@media (max-width: 520px) {
  select, input[type="text"], input[type="number"], input[type="color"] { font-size: 16px; }
}

/* 折叠块（解构） */
.fold { border-radius: var(--radius-sm); }
.fold > summary {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  font-size: var(--f-12);
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 3.5px solid transparent;
  border-bottom: 3.5px solid transparent;
  transition: transform 160ms ease-out;
}
.fold[open] > summary::before { transform: rotate(90deg); }
.fold[open] > summary { margin-bottom: 6px; }

/* 画布浮层提示（原来那行文字改成浮动提示） */
.canvas-hint {
  position: absolute;
  left: 12px;
  bottom: 14px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 2px rgba(16, 17, 20, 0.08);
  font-size: var(--f-12);
  color: var(--muted);
  pointer-events: none;
}
