/* ============================================================
   拾色 · 样式
   设计令牌由 JS 通过 CSS 变量动态注入（--bg/--fg/--accent 等）
   ============================================================ */

:root {
  /* 默认主题（米白），由 deriveTheme 覆盖 */
  --bg: #eceff1;
  --fg: #1a1b1e;
  --fg-muted: rgba(26, 27, 30, 0.58);
  --fg-faint: rgba(26, 27, 30, 0.38);
  --accent: #0d9488;
  --accent-soft: rgba(13, 148, 136, 0.1);
  --panel: rgba(255, 255, 255, 0.66);
  --panel-border: rgba(18, 20, 24, 0.1);
  --shadow: rgba(20, 24, 32, 0.1);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --dur: 0.45s;
}

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

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

body {
  font-family: "Inter", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Noto Sans SC", system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur) ease, color var(--dur) ease;
}

/* 顶部氛围光晕：颜色可平滑过渡（用 mask 抠出径向形状） */
.glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-color: var(--accent-soft);
  -webkit-mask-image: radial-gradient(880px 420px at 78% -6%, #000 0%, transparent 60%);
  mask-image: radial-gradient(880px 420px at 78% -6%, #000 0%, transparent 60%);
  transition: background-color var(--dur) ease;
}

/* ---------- 玻璃面板 ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 1px 2px var(--shadow), 0 16px 40px -20px var(--shadow);
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
  transition: background-color var(--dur) ease, border-color var(--dur) ease,
    box-shadow var(--dur) ease;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
  transition: background-color var(--dur) ease, border-color var(--dur) ease;
}

.topbar-inner {
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent) 50%, var(--bg) 50%);
  border: 1px solid var(--panel-border);
  transition: background-color var(--dur) ease;
}

.brand-name {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.brand-sub {
  font-size: 11px;
  color: var(--fg-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease,
    filter 0.2s ease;
}

.btn .icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  transition: background-color var(--dur) ease, filter 0.2s ease;
}

.btn-primary:hover {
  filter: brightness(1.1);
}

.btn-primary:active {
  filter: brightness(0.95);
}

.btn-ghost {
  background: var(--panel);
  border-color: var(--panel-border);
  color: var(--fg);
}

.btn-ghost:hover {
  border-color: var(--accent-text);
  color: var(--accent-text);
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--fg);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.icon-btn:hover {
  color: var(--accent-text);
  border-color: var(--accent-text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

.btn:focus-visible,
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-link {
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 4px;
}

.btn-link:hover {
  color: var(--accent-text);
}

/* ---------- 主内容 ---------- */
.main {
  padding: 48px 24px 104px;
}

.hero {
  margin-bottom: 32px;
}

.hero-eyebrow {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-muted);
}

.hero-title {
  margin-top: 10px;
  font-size: clamp(28px, 4.5vw, 42px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.hero-desc {
  margin-top: 14px;
  max-width: 580px;
  font-size: 15px;
  line-height: 1.75;
  color: var(--fg-muted);
}

/* ---------- 当前颜色卡片 ---------- */
.current-card {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 24px;
  margin-bottom: 24px;
}

.current-swatch {
  position: relative;
  flex: none;
  width: 120px;
  height: 120px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  background: var(--bg);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.2s ease, background-color var(--dur) ease;
}

.current-swatch:hover {
  transform: translateY(-2px);
}

.current-swatch .swatch-check {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 34px;
  height: 34px;
  color: var(--fg);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.current-swatch:hover .swatch-check {
  opacity: 0.85;
}

.current-info {
  min-width: 0;
  flex: 1;
}

.current-name {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.current-values {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.current-values code {
  font-family: "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--panel-border);
  color: var(--fg);
}

.contrast-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  padding: 6px 14px 6px 6px;
  border-radius: 999px;
  font-size: 12.5px;
  color: var(--fg-muted);
  background: var(--accent-soft);
  border: 1px solid var(--panel-border);
}

.contrast-sample {
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg);
  color: var(--fg);
  font-size: 11px;
  font-weight: 700;
  transition: background-color var(--dur) ease, color var(--dur) ease;
}

.badge {
  font-weight: 700;
}

.badge.ok { color: var(--accent); }
.badge.warn { color: #f59e0b; }
.badge.bad { color: #ef4444; }

.current-actions {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- 双栏布局 ---------- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.section-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

/* ---------- 手动配色 ---------- */
.picker-card,
.recent-card {
  padding: 24px;
}

.picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.native-picker {
  position: relative;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.native-picker:hover {
  border-color: var(--accent);
}

.native-picker input[type="color"] {
  position: absolute;
  inset: -10px;
  width: 68px;
  height: 68px;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
}

.hex-input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--accent-soft);
  color: var(--fg);
  font-family: "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.hex-input:focus {
  border-color: var(--accent);
}

.hex-input.invalid {
  border-color: #ef4444;
}

.hex-input.invalid:focus {
  border-color: #ef4444;
}

.sliders {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 22px;
}

.slider-row {
  display: grid;
  grid-template-columns: 52px 1fr 46px;
  align-items: center;
  gap: 12px;
}

.slider-row label {
  font-size: 13px;
  color: var(--fg-muted);
}

.slider-row output {
  font-size: 12.5px;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  text-align: right;
  color: var(--fg);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px var(--shadow);
  cursor: grab;
  transition: transform 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--accent);
  box-shadow: 0 1px 4px var(--shadow);
  cursor: grab;
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* ---------- 最近使用 ---------- */
.recent-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 16px;
}

.recent-chip {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.recent-chip:hover {
  transform: translateY(-2px);
}

.recent-chip .remove {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  border: 0;
  background: var(--fg);
  color: var(--bg);
  font-size: 10px;
  line-height: 1;
  display: none;
  place-items: center;
  cursor: pointer;
}

.recent-chip:hover .remove {
  display: grid;
}

.recent-empty {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--fg-faint);
}

/* ---------- 页脚 ---------- */
.footer {
  padding: 0 24px 32px;
  text-align: center;
  font-size: 12.5px;
  color: var(--fg-faint);
}

.footer kbd {
  font-family: inherit;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--fg-muted);
}

/* ---------- 抽屉 ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgba(10, 12, 16, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  width: min(448px, 96vw);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--panel-border);
  backdrop-filter: blur(22px) saturate(1.4);
  -webkit-backdrop-filter: blur(22px) saturate(1.4);
  box-shadow: -24px 0 60px -30px var(--shadow);
  transform: translateX(104%);
  visibility: hidden;
  transition: transform 0.34s cubic-bezier(0.32, 0.72, 0.32, 1),
    background-color var(--dur) ease, border-color var(--dur) ease;
}

.drawer.open {
  transform: translateX(0);
  visibility: visible;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 14px;
}

.drawer-title {
  font-size: 18px;
  font-weight: 700;
}

.drawer-sub {
  margin-top: 3px;
  font-size: 12px;
  color: var(--fg-muted);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 14px;
}

.tab {
  flex: none;
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.tab:hover {
  color: var(--fg);
  border-color: var(--accent-text);
}

.tab.active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 20px 28px;
  overscroll-behavior: contain;
}

/* 分类分组 */
.category-group {
  margin-bottom: 22px;
}

.category-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}

.category-name {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.category-count {
  font-size: 11px;
  color: var(--fg-faint);
}

.swatch-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px 12px;
}

.swatch {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.swatch-block {
  position: relative;
  display: block;
  width: 100%;
  height: 78px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  overflow: hidden;
  transition: transform 0.16s ease;
}

.swatch:hover .swatch-block {
  transform: translateY(-2px);
}

.swatch:focus-visible {
  outline: none;
}

.swatch:focus-visible .swatch-block {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.swatch-check-icon {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.swatch.selected .swatch-check-icon {
  opacity: 1;
}

.swatch-name {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s ease;
}

.swatch.selected .swatch-name {
  color: var(--accent-text);
  font-weight: 600;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 80;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 32px -12px var(--shadow);
  font-size: 13px;
  color: var(--fg);
  opacity: 0;
  transform: translate(-50%, 16px);
  pointer-events: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .current-card {
    flex-wrap: wrap;
  }

  .current-actions {
    flex-direction: row;
    width: 100%;
  }

  .current-actions .btn {
    flex: 1;
    justify-content: center;
  }
}

@media (max-width: 560px) {
  .topbar-inner {
    padding: 0 16px;
  }

  .brand-sub {
    display: none;
  }

  .btn-ghost {
    padding: 0 12px;
  }

  .main {
    padding: 32px 16px 96px;
  }

  .current-swatch {
    width: 88px;
    height: 88px;
  }

  .drawer {
    width: 100vw;
  }
}

/* 桌面端点击抽屉时无需遮罩（可见页面内容） */
@media (min-width: 1024px) {
  .backdrop {
    display: none;
  }
}

/* ---------- 动效偏好 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
