/* =========================================================
   学术配色 · Nature-Level Palettes (Magazine Edition)
   Noto Serif SC + Fraunces 双衬线 · 色带 hero · 卡片编号
   ========================================================= */

@import url('https://fonts.googleapis.cn/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;0,9..144,700;1,9..144,400;1,9..144,500&family=Noto+Serif+SC:wght@400;500;600;700;900&display=swap');

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

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 14px;
  --radius-sm: 8px;
  --serif-cn: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', 'STSong', 'SimSun', serif;
  --serif-en: 'Fraunces', 'Playfair Display', Georgia, 'Times New Roman', serif;
  --sans-cn: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  --mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Consolas', 'Liberation Mono', monospace;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Dark (default) ---------- */
html[data-theme='dark'] {
  --bg: #0a0a12;
  --bg-blur: rgba(10, 10, 18, 0.88);
  --surface: #14141e;
  --surface-2: #1c1c2a;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e8e8ee;
  --text-strong: #ffffff;
  --text-dim: #8a8a96;
  --text-faint: #55555f;
  --pill-active-bg: #ffffff;
  --pill-active-text: #0a0a12;
  --btn-bg: rgba(255, 255, 255, 0.04);
  --btn-bg-active: rgba(255, 255, 255, 0.10);
  --tag-neutral-bg: rgba(255, 255, 255, 0.06);
  --tag-cb-safe-bg: rgba(0, 158, 115, 0.18);
  --tag-cb-safe-fg: #4dd0a8;
  --tag-cb-warn-bg: rgba(230, 159, 0, 0.18);
  --tag-cb-warn-fg: #e6a53a;
  --tag-print-bg: rgba(78, 121, 167, 0.20);
  --tag-print-fg: #7ba7cc;
  --code-bg: rgba(0, 0, 0, 0.28);
  --code-fg: #a8d4a0;
  --toast-bg: rgba(255, 255, 255, 0.96);
  --toast-fg: #0a0a12;
  --chip-border: rgba(255, 255, 255, 0.08);
  --dropcap-fg: #ffffff;
  --num-badge-bg: rgba(0, 0, 0, 0.42);
  --num-badge-fg: rgba(255, 255, 255, 0.94);
  --hairline: rgba(255, 255, 255, 0.10);
}

/* ---------- Light ---------- */
html[data-theme='light'] {
  --bg: #f5f5f0;
  --bg-blur: rgba(245, 245, 240, 0.88);
  --surface: #ffffff;
  --surface-2: #eeeeea;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.16);
  --text: #1a1a24;
  --text-strong: #0a0a12;
  --text-dim: #5a5a66;
  --text-faint: #9a9aa0;
  --pill-active-bg: #1a1a24;
  --pill-active-text: #ffffff;
  --btn-bg: rgba(0, 0, 0, 0.04);
  --btn-bg-active: rgba(0, 0, 0, 0.08);
  --tag-neutral-bg: rgba(0, 0, 0, 0.05);
  --tag-cb-safe-bg: rgba(0, 158, 115, 0.14);
  --tag-cb-safe-fg: #067a5c;
  --tag-cb-warn-bg: rgba(213, 94, 0, 0.14);
  --tag-cb-warn-fg: #a24700;
  --tag-print-bg: rgba(33, 102, 172, 0.14);
  --tag-print-fg: #1a5a94;
  --code-bg: #f3f3ee;
  --code-fg: #2f5d2a;
  --toast-bg: #1a1a24;
  --toast-fg: #ffffff;
  --chip-border: rgba(0, 0, 0, 0.10);
  --dropcap-fg: #1a1a24;
  --num-badge-bg: rgba(255, 255, 255, 0.86);
  --num-badge-fg: #1a1a24;
  --hairline: rgba(0, 0, 0, 0.10);
}

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

body {
  font-family: var(--serif-cn);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.28s var(--ease), color 0.28s var(--ease);
  font-feature-settings: "kern" 1, "liga" 1;
}

/* ============ Header ============ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-blur);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--border);
  padding-top: var(--safe-top);
}

.header-inner {
  padding: 14px 16px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.header-brand { flex: 1; min-width: 0; }

.header-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.header-title h1 {
  font-family: var(--serif-cn);
  font-size: 1.42rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-strong);
  line-height: 1.15;
}

.header-title .sub {
  font-family: var(--serif-en);
  font-style: italic;
  font-size: 0.78rem;
  color: var(--text-dim);
  letter-spacing: 0.4px;
  font-weight: 400;
  font-optical-sizing: auto;
}

.header-desc {
  font-family: var(--serif-cn);
  font-size: 0.76rem;
  color: var(--text-dim);
  margin-bottom: 12px;
  line-height: 1.7;
  font-weight: 400;
  letter-spacing: 0.2px;
}

/* Theme toggle */
.theme-toggle {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.24s var(--ease), background 0.2s;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:active { background: var(--btn-bg-active); transform: scale(0.94); }

/* ============ Category Nav ============ */
.cat-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 16px 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  scroll-snap-type: x proximity;
}
.cat-nav::-webkit-scrollbar { display: none; }

.cat-tab {
  flex-shrink: 0;
  min-height: 36px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-family: var(--serif-cn);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.22s var(--ease);
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  scroll-snap-align: start;
  letter-spacing: 0.5px;
}

.cat-tab.active {
  background: var(--pill-active-bg);
  color: var(--pill-active-text);
  border-color: var(--pill-active-bg);
  font-weight: 600;
}

/* ============ Main ============ */
.main {
  padding: 18px 14px calc(76px + var(--safe-bottom));
  max-width: 640px;
  margin: 0 auto;
}

/* Category description */
.cat-desc {
  font-family: var(--serif-cn);
  font-size: 0.9rem;
  color: var(--text-dim);
  margin: 4px 4px 20px;
  line-height: 1.75;
  font-weight: 400;
  letter-spacing: 0.3px;
}

.cat-section { display: none; animation: fadeUp 0.35s var(--ease); }
.cat-section.active { display: block; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============ Palette Card (Magazine Hero) ============ */
.palette-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 18px;
  overflow: hidden;
  transition: border-color 0.2s, transform 0.24s var(--ease);
}
.palette-card:active { border-color: var(--border-strong); }

/* --- Hero: 色带做视觉锚点 --- */
.palette-hero {
  position: relative;
  height: 120px;
  overflow: hidden;
}

.palette-hero .color-strip {
  height: 100%;
  border-radius: 0;
}

/* 编号 Nº 01/06 叠在色带右上角 */
.palette-num {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 5px 10px 5px 11px;
  border-radius: 14px;
  background: var(--num-badge-bg);
  color: var(--num-badge-fg);
  font-family: var(--serif-en);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.6px;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 2;
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  line-height: 1.2;
  pointer-events: none;
}
.palette-num .num-symbol {
  font-style: italic;
  font-size: 0.92em;
  opacity: 0.75;
  margin-right: 1px;
}
.palette-num .num-total {
  font-size: 0.82em;
  opacity: 0.55;
  font-weight: 500;
}

/* --- Head 信息层 --- */
.palette-head {
  padding: 16px 16px 12px;
}

.palette-name {
  font-family: var(--serif-cn);
  font-size: 1.28rem;
  font-weight: 700;
  color: var(--text-strong);
  margin-bottom: 5px;
  line-height: 1.28;
  letter-spacing: 0.4px;
}

.palette-en {
  font-family: var(--serif-en);
  font-style: italic;
  font-size: 0.88rem;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0.2px;
  margin-bottom: 10px;
  font-optical-sizing: auto;
}

.palette-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px 8px;
  font-size: 0.68rem;
  margin-bottom: 12px;
}

.tag {
  padding: 3px 9px;
  border-radius: 5px;
  font-weight: 500;
  letter-spacing: 0.2px;
  line-height: 1.35;
  font-family: var(--sans-cn);
}

.tag-cb-safe { background: var(--tag-cb-safe-bg); color: var(--tag-cb-safe-fg); }
.tag-cb-warn { background: var(--tag-cb-warn-bg); color: var(--tag-cb-warn-fg); }
.tag-print   { background: var(--tag-print-bg);   color: var(--tag-print-fg); }
.tag-n       { background: var(--tag-neutral-bg); color: var(--text-dim); font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* 卡片描述 */
.palette-desc {
  font-family: var(--serif-cn);
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.75;
  letter-spacing: 0.2px;
  font-weight: 400;
}

/* ============ Color Strip ============ */
.color-strip {
  display: flex;
  height: 56px;
}

.color-strip > div {
  flex: 1;
  cursor: pointer;
  transition: flex 0.26s var(--ease), opacity 0.2s;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  -webkit-tap-highlight-color: transparent;
}

.color-strip > div:active {
  flex: 2.2;
  opacity: 0.95;
}

.color-strip > div .strip-hex {
  font-size: 0.62rem;
  font-family: var(--mono);
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  letter-spacing: 0.4px;
}

.color-strip > div:active .strip-hex { opacity: 1; }

@media (hover: hover) {
  .color-strip > div:hover { flex: 2.2; opacity: 0.95; }
  .color-strip > div:hover .strip-hex { opacity: 1; }
}

/* ============ Color List ============ */
.color-list {
  padding: 4px 0 0;
  border-top: 1px solid var(--hairline);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  min-height: 60px;
  border-top: 1px solid var(--hairline);
  cursor: pointer;
  transition: background 0.15s;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.color-row:first-child { border-top: none; }
.color-row:active { background: var(--btn-bg-active); }

.color-chip {
  width: 40px;
  height: 40px;
  border-radius: 9px;
  flex-shrink: 0;
  border: 1px solid var(--chip-border);
}

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

.color-info .cname {
  font-family: var(--serif-cn);
  font-size: 0.94rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
  letter-spacing: 0.3px;
}

.color-info .cvals {
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.color-copy-icon {
  font-family: var(--serif-en);
  font-style: italic;
  font-size: 0.75rem;
  color: var(--text-faint);
  flex-shrink: 0;
  padding: 4px 6px;
  letter-spacing: 0.4px;
}

/* ============ Export Section ============ */
.export-section {
  border-top: 1px solid var(--hairline);
  padding: 12px 12px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

@media (min-width: 480px) {
  .export-section { grid-template-columns: repeat(4, 1fr); }
}

.export-btn {
  min-height: 42px;
  padding: 9px 6px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text-dim);
  font-family: var(--serif-en);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.3px;
}
.export-btn.cn { font-family: var(--serif-cn); letter-spacing: 0.4px; font-size: 0.78rem; }

.export-btn:active {
  background: var(--btn-bg-active);
  color: var(--text-strong);
}

/* ============ Code Block ============ */
.code-block {
  display: none;
  border-top: 1px solid var(--hairline);
  padding: 12px 14px;
  background: var(--code-bg);
  max-height: 320px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.code-block.show { display: block; }

.code-block pre {
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.65;
  color: var(--code-fg);
  white-space: pre-wrap;
  word-break: break-all;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: calc(88px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--toast-bg);
  color: var(--toast-fg);
  padding: 10px 22px;
  border-radius: 22px;
  font-family: var(--serif-cn);
  font-size: 0.84rem;
  font-weight: 600;
  letter-spacing: 0.4px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s var(--ease);
  z-index: 200;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============ Bottom Bar ============ */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-blur);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + var(--safe-bottom));
  display: flex;
  gap: 8px;
  z-index: 90;
}

.bottom-btn {
  flex: 1;
  min-height: 44px;
  padding: 10px 8px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font-family: var(--serif-cn);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.6px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.bottom-btn:active {
  background: var(--btn-bg-active);
  color: var(--text-strong);
}

/* ============ Footer ============ */
.footer-note {
  font-family: var(--serif-cn);
  font-size: 0.74rem;
  color: var(--text-faint);
  text-align: center;
  padding: 26px 16px 10px;
  line-height: 1.85;
  letter-spacing: 0.3px;
  font-style: italic;
}
.footer-note em {
  font-family: var(--serif-en);
  font-style: italic;
  letter-spacing: 0.2px;
}

/* ============ Responsive ============ */
@media (min-width: 768px) {
  .main { max-width: 800px; }
  .header-inner { padding: 16px 22px 0; }
  .cat-nav { padding: 2px 22px 14px; }
  .header-title h1 { font-size: 1.6rem; }
  .palette-hero { height: 140px; }
  .palette-name { font-size: 1.42rem; }
  .color-strip { height: 64px; }
}
