/* =========================================================
   Gradient tool — 渐变色调试（Figma 式布局）
   严格遵循 docs/DESIGN-SPEC.md：
   - 卡片: --bg-white + 1px --border-light + --r-xl + --sh-sm
   - 强调色: var(--accent)；滑块/输入复用 .pal-slider / .color-hex-input /
     .color-circle / .pal-slider-num 规范类（tools.css / styles.css）
   - 禁止硬编码颜色/圆角/阴影/字号（代码块深色用 --surface-dark 令牌）
   - 死代码零容忍
   ========================================================= */

/* ---------- 布局：两栏 stage（工具页 §3.8） ---------- */
.grad-stage {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}

/* ---------- 左：预览卡（卡片体系 §3.1） ---------- */
.grad-preview-card {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--r-xl);
  padding: var(--sp-4);
  box-shadow: var(--sh-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.grad-preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.grad-preview-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
.grad-preview-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.grad-preview-title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: var(--r-full);
  background: var(--accent);
}
.grad-preview-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* 预览画布 + 透明棋盘格 */
.grad-preview {
  position: relative;
  width: 100%;
  aspect-ratio: 8 / 3;
  max-height: 200px;
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--border);
  background-color: var(--bg-white);
  background-image:
    linear-gradient(45deg, var(--border-light) 25%, transparent 25%),
    linear-gradient(-45deg, var(--border-light) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--border-light) 75%),
    linear-gradient(-45deg, transparent 75%, var(--border-light) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.grad-preview canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  border-radius: inherit;
}
/* 浏览器原生 CSS 渐变渲染层 */
.grad-preview-render {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
}

/* ---------- Figma 式色标轨道 ---------- */
.grad-track-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 7px 2px 0;
}
.grad-track {
  position: relative;
  height: 12px;
  border-radius: var(--r-full);
  box-shadow: inset 0 0 0 1px var(--border);
  cursor: copy;
  outline: none;
  touch-action: none;
}
.grad-track:focus-visible {
  box-shadow: inset 0 0 0 1px var(--accent), 0 0 0 3px var(--accent-tint);
}
.grad-handle {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 15px;
  height: 15px;
  border-radius: var(--r-full);
  border: 2px solid var(--bg-white);
  background-color: transparent !important;
  box-shadow: 0 0 0 1px var(--border), var(--sh-sm);
  cursor: grab;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  background-clip: padding-box;
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.grad-handle:hover { transform: translate(-50%, -50%) scale(1.15); }
.grad-handle:active { cursor: grabbing; }
.grad-handle.is-active {
  transform: translate(-50%, -50%) scale(1.25);
  box-shadow: 0 0 0 2px var(--accent), var(--sh-sm);
  z-index: 1;
}
.grad-handle.is-dragging,
.grad-handle.is-dragging:hover {
  transition: none !important;
  cursor: grabbing !important;
  transform: translate(-50%, -50%) !important;
  box-shadow: 0 0 0 2px var(--accent), var(--sh-sm) !important;
  z-index: 2 !important;
}
.grad-track-hint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--text-soft);
}

/* ---------- 阶梯色板预览 ---------- */
.grad-steps {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.grad-steps-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}
.grad-steps-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
.grad-steps-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}
.grad-step-tabs {
  display: inline-flex;
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--r-full);
  padding: 2px;
  gap: 2px;
}
.grad-step-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-mono);
  border-radius: var(--r-full);
  padding: 3px 10px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.grad-step-tab:hover { color: var(--accent); }
.grad-step-tab.is-active {
  background: var(--bg-white);
  color: var(--accent);
  box-shadow: var(--sh-sm);
}
/* 阶梯色板：与首页色卡展现一致 —— 横向色条均分，hover 展开 + HEX 浮层
   高度取紧凑值以适配单屏工具页 */
.grad-steps-row {
  display: flex;
  height: 88px;
  border: 1px solid var(--border-light);
  border-radius: var(--r-md);
  overflow: hidden;
}
.grad-step-swatch {
  appearance: none;
  flex: 1;
  min-width: 0;
  position: relative;
  border: 0;
  cursor: pointer;
  padding: 0;
  transition: flex var(--t-fast);
}
.grad-step-swatch:hover { flex: 2; }
/* HEX 浮层（与 .palette-preview-bar::after 一致）：hover 显示色号 */
.grad-step-swatch::after {
  content: attr(data-hex);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--overlay-dark);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast);
  font-family: var(--font-mono);
  z-index: 5;
}
.grad-step-swatch:hover::after { opacity: 1; }

/* ---------- 选中色标详情（次级面板：--bg-alt 底，突出当前色标） ---------- */
.grad-stop-detail {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
}
.grad-detail-color {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 0;
}
.grad-detail-circle {
  width: 32px;
  height: 32px;
  flex: none;
}
.grad-detail-hex { flex: 1; min-width: 0; }
.grad-stop-remove {
  appearance: none;
  flex: none;
  border: 1px solid var(--border-light);
  background: var(--bg-white);
  color: var(--text-muted);
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.grad-stop-remove:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}
.grad-stop-remove:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- CSS 输出区（深色代码块：精简版） ---------- */
.grad-output {
  position: relative;
  display: flex;
  align-items: stretch;
  background: var(--surface-dark);
  border: 1px solid var(--border-dark);
  border-radius: var(--r-md);
  overflow: hidden;
}
.grad-output-code {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  margin: 0;
  font: 500 0.78rem/1.55 var(--font-mono);
  color: var(--text-on-dark);
  white-space: pre-wrap;
  word-break: break-all;
  user-select: all;
  scrollbar-width: thin;
  scrollbar-color: var(--border-dark) transparent;
}

/* 复制按钮：右侧嵌入式（与代码同行，深底胶囊） */
.grad-output-copy {
  appearance: none;
  flex: none;
  display: inline-flex;
  align-items: center;
  padding: 0 14px;
  margin: 6px 6px 6px 0;
  border: 1px solid var(--border-dark);
  background: var(--surface-dark-2);
  color: var(--text-on-dark-muted);
  border-radius: var(--r-sm);
  font-size: 0.72rem;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.grad-output-copy:hover {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}
.grad-output-copy.is-copied {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

/* ---------- 右：控制面板（单屏紧凑） ---------- */
.grad-controls {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.grad-card {
  background: var(--bg-white);
  border: 1px solid var(--border-light);
  border-radius: var(--r-xl);
  padding: var(--sp-4);
  box-shadow: var(--sh-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.grad-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.grad-card-title::before {
  content: "";
  flex: none;
  width: 3px;
  height: 13px;
  border-radius: var(--r-full);
  background: var(--accent);
}
.grad-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

/* 翻转 / 导出小按钮 */
.grad-mini-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border-light);
  background: var(--bg-white);
  color: var(--text-muted);
  border-radius: var(--r-full);
  padding: 3px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
  white-space: nowrap;
}
.grad-mini-btn svg { display: block; }
.grad-mini-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}

/* ---------- 类型 / 插值 切换按钮（胶囊分段控件 §3.3：--bg-alt 凹槽 + --r-full） ---------- */
.grad-type-row {
  display: flex;
  width: 100%;
  gap: 4px;
  padding: 4px;
  background: var(--bg-alt);
  border: 1px solid var(--border-light);
  border-radius: var(--r-full);
}
.grad-type-btn {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  padding: 6px 4px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0;
  border: none;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  outline: none;
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
  line-height: 1.2;
}
.grad-type-btn:hover { background: var(--accent-tint); color: var(--accent); }
.grad-type-btn:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.grad-type-btn:active { transform: scale(0.96); }
.grad-type-btn.is-active {
  background: var(--bg-white);
  color: var(--accent);
  font-weight: 700;
  box-shadow: var(--sh-sm);
}

/* ---------- 参数分组（字段间 vertical 节奏） ---------- */
.grad-field {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

/* ---------- 预设（卡片体系色卡） ---------- */
.grad-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-2);
}
.grad-preset {
  position: relative;
  height: 40px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-light);
  cursor: pointer;
  overflow: hidden;
  transition: border-color var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast);
  padding: 0;
  background: var(--bg-white);
}
.grad-preset:hover { transform: translateY(-1px); box-shadow: var(--sh-sm); }
.grad-preset.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-tint); }

/* ---------- 响应式（规范断点：900 / 640） ---------- */
@media (max-width: 900px) {
  .grad-stage { grid-template-columns: 1fr; gap: var(--sp-4); }
  .grad-preview { aspect-ratio: 16 / 6; max-height: none; }
}
@media (max-width: 640px) {
  .grad-card { padding: var(--sp-4); }
  .grad-preview-card { padding: var(--sp-4); }
  .grad-detail-color { flex-wrap: wrap; }
}
