/* 随机头像实验室 · Notion Avatar 风格
 * 白底黑边 + 硬偏移投影（贴纸感）+ 手绘装饰 + 圆形头像
 * 干净极简，强字重对比，俏皮但有秩序 */
:root {
  --bg: #f7f6f2;
  --card: #ffffff;
  --ink: #1a1815;
  --sub: #847d72;
  --line: #1a1815;
  --accent: #2f6df6;
  --hl: #ffd43b;
  --pink: #ff8fa3;
  --green: #40c463;
  --radius: 18px;
  --hard: 4px 4px 0 var(--ink);
  --hard-sm: 3px 3px 0 var(--ink);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "PingFang SC", "Segoe UI", "Helvetica Neue", "Noto Sans SC", sans-serif;
  max-width: 1000px; margin: 0 auto; padding: 36px 20px 90px;
  line-height: 1.65;
}
/* 纸面细点纹理（极淡，营造手账质感） */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: radial-gradient(rgba(26,24,21,.05) 1px, transparent 1px);
  background-size: 22px 22px;
}
body > * { position: relative; z-index: 1; }

/* ================= 页头 ================= */
.page-head {
  position: relative; overflow: hidden;
  background: var(--card);
  border: 2px solid var(--line); border-radius: 22px;
  padding: 34px 32px 26px; margin-bottom: 22px;
  box-shadow: 5px 5px 0 var(--ink);
}
.page-head h1 {
  position: relative; display: inline-block;
  font-size: 34px; font-weight: 900; letter-spacing: 1px; line-height: 1.25;
}
/* 手绘波浪下划线 */
.page-head h1 .squiggle { position: absolute; left: 0; bottom: -8px; width: 100%; height: 10px; }
.page-head h1 .squiggle path { fill: none; stroke: var(--hl); stroke-width: 5; stroke-linecap: round; }
.page-head .spark { position: absolute; pointer-events: none; }
.page-head .spark svg { display: block; }
.page-head p { color: var(--sub); margin-top: 16px; font-size: 14px; max-width: 640px; }
.page-head p b { color: var(--ink); }
.head-avatars { display: flex; gap: 12px; margin-top: 22px; flex-wrap: wrap; }
.head-avatar {
  width: 52px; height: 52px; border-radius: 50%; overflow: hidden; flex: none;
  border: 2px solid var(--line); background: #fff;
  box-shadow: var(--hard-sm);
  transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s;
}
.head-avatar:hover { transform: translateY(-5px) rotate(-6deg); box-shadow: 5px 6px 0 var(--ink); }
.head-avatar svg, .head-avatar img { width: 100%; height: 100%; display: block; }

/* 星光闪烁动画 */
@keyframes twinkle { 0%,100% { transform: scale(1) rotate(0); opacity: .95; } 50% { transform: scale(.72) rotate(18deg); opacity: .55; } }
.page-head .spark { animation: twinkle 2.6s ease-in-out infinite; }
.page-head .spark.s2 { animation-delay: .7s; }
.page-head .spark.s3 { animation-delay: 1.3s; }

/* ================= 工具栏 ================= */
.toolbar {
  position: sticky; top: 12px; z-index: 30;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--card);
  border: 2px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 22px;
  box-shadow: var(--hard);
}
#nameInput, #styleSelect {
  flex: 1; min-width: 190px; padding: 10px 14px;
  border: 2px solid var(--line); border-radius: 12px; font-size: 15px; font-weight: 600;
  background: #fff; color: var(--ink); transition: box-shadow .15s;
}
#styleSelect { flex: 0 1 210px; height: 44px; cursor: pointer; }
#nameInput:focus, #styleSelect:focus { outline: none; box-shadow: var(--hard-sm); }
.selected-avatar-preview {
  width: 54px; height: 54px; flex: none; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
  box-shadow: var(--hard-sm);
}
.selected-avatar-preview svg,
.selected-avatar-preview img,
.selected-avatar-preview .expert-portrait {
  width: 100%; height: 100%; display: block; object-fit: cover; border-radius: 9px;
}
.btn {
  padding: 9px 18px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; color: var(--ink); font-size: 14px; font-weight: 700; cursor: pointer;
  transition: all .15s; box-shadow: var(--hard-sm);
}
.btn:hover { background: var(--ink); color: #fff; transform: translate(-1px,-1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--hl); }
.btn.primary:hover { background: var(--ink); color: var(--hl); }
.hint { width: 100%; color: var(--sub); font-size: 12.5px; }
.collapse-info { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--sub); white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ================= 分类导航 ================= */
.cat-row { display: flex; align-items: baseline; gap: 12px; margin: 34px 2px 12px; }
.cat-label {
  font-size: 13px; font-weight: 900; letter-spacing: 3px; color: var(--ink);
  flex: none; background: var(--hl); border: 2px solid var(--line);
  padding: 2px 12px; border-radius: 999px; box-shadow: var(--hard-sm);
}
.cat-note { font-size: 12.5px; color: var(--sub); font-weight: 600; }
.cat-row::after { content: ""; flex: 1; height: 2px; background: var(--line); align-self: center; border-radius: 2px; opacity: .15; }

/* ================= 卡片 / 分区 ================= */
.card {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px; margin-bottom: 22px;
  box-shadow: var(--hard);
}
.collapsible { scroll-margin-top: 92px; }
.sec-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h2 { font-size: 19px; font-weight: 900; letter-spacing: .3px; }
.tag {
  font-size: 11.5px; font-weight: 800; padding: 3px 12px; border-radius: 999px;
  background: var(--hl); color: var(--ink); border: 1.5px solid var(--line);
}
.tag.warn { background: var(--pink); }
.sec-desc { color: var(--sub); font-size: 13px; margin: 8px 0 16px; line-height: 1.75; }

.sec-toggle {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  cursor: pointer; user-select: none; margin: -6px -8px 0; padding: 6px 8px;
  border-radius: 12px; transition: background .15s;
}
.sec-toggle:hover { background: rgba(255,212,59,.18); }
.chevron {
  width: 10px; height: 10px; flex: none; margin-left: auto;
  border-right: 3px solid var(--ink); border-bottom: 3px solid var(--ink);
  transform: rotate(45deg); transition: transform .28s ease;
}
.collapsed .chevron { transform: rotate(-45deg); }
.sec-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .34s ease; }
.collapsed .sec-body { grid-template-rows: 0fr; }
.sec-inner { overflow: hidden; min-height: 0; }
.collapsed .sec-inner { visibility: hidden; transition: visibility 0s .34s; }

/* ================= 头像网格 ================= */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 14px; }
.avatar-card {
  aspect-ratio: 1; border: 2px solid var(--line); border-radius: 16px; background: #fff;
  cursor: pointer; padding: 7px; display: flex; align-items: center; justify-content: center;
  transition: transform .18s cubic-bezier(.34,1.56,.64,1), box-shadow .18s;
}
.avatar-card:hover { transform: translateY(-4px) rotate(-1.5deg); box-shadow: var(--hard); }
.avatar-card svg, .avatar-card img { width: 100%; height: 100%; display: block; border-radius: 10px; }
.grid.dense { grid-template-columns: repeat(auto-fill, minmax(66px, 1fr)); gap: 9px; }
.grid.dense .avatar-card { padding: 4px; border-radius: 12px; }

/* ================= 官方原版区 ================= */
.official-hero { display: flex; gap: 18px; align-items: center; margin-bottom: 16px; }
.official-hero-img {
  width: 122px; height: 122px; flex: none;
  border: 2px solid var(--line); border-radius: 16px; background: #fff; padding: 6px;
  box-shadow: var(--hard-sm);
}
.official-hero-meta { color: var(--sub); font-size: 13px; line-height: 1.9; }
.official-hero-meta b { color: var(--ink); font-size: 16px; }

/* ================= 历史人物图鉴 ================= */
.famous-section { background: linear-gradient(180deg, #ffffff 0%, #fdf9ef 100%); }
.famous-grid { grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 15px; }
.famous-card {
  flex-direction: column; align-items: center; justify-content: flex-start;
  padding: 12px 8px 10px; gap: 8px; text-align: center;
}
.famous-card svg { width: 84px; height: 84px; flex: none; display: block; border-radius: 50%; }
.famous-card .name {
  font-size: 11.5px; line-height: 1.3; color: var(--sub); font-weight: 600;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.famous-card:hover .name { color: var(--ink); }
.famous-hidden { border-color: var(--line); background: #fffbe8; position: relative; }
.famous-hidden::after {
  content: "隐"; position: absolute; top: 7px; right: 7px; font-size: 9px; font-weight: 800;
  background: var(--ink); color: var(--hl); padding: 2px 6px; border-radius: 999px; line-height: 1.2;
}
.famous-hidden .name { color: #8a6a1a; }
.tag-hidden { font-size: 9px; background: var(--hl); color: var(--ink); padding: 1px 5px; border-radius: 4px; margin-left: 3px; font-weight: 800; border: 1px solid var(--line); }
.famous-note { margin-top: 16px; font-size: 12.5px; font-weight: 600; color: var(--sub); text-align: center; padding: 4px 0; }

/* ================= 像素专家肖像 ================= */
.expert-section { background: #fff; }
.gender-segment {
  width: max-content; display: grid; grid-template-columns: repeat(3, 58px);
  margin: 0 auto 18px; padding: 3px; border: 2px solid var(--line);
  border-radius: 8px; background: #f0eee8;
}
.gender-option {
  height: 34px; border: 0; border-radius: 5px; background: transparent;
  color: var(--sub); font-size: 13px; font-weight: 800; cursor: pointer;
}
.gender-option.active { background: var(--ink); color: #fff; }
.gender-option:focus-visible { outline: 3px solid var(--hl); outline-offset: 2px; }
.expert-grid {
  display: grid; grid-template-columns: repeat(4, 124px);
  justify-content: center; gap: 18px; margin: 0 auto;
}
.expert-card {
  width: 124px; height: 124px; padding: 0;
  display: block; border: 0; border-radius: 10px; background: transparent;
  box-shadow: none; cursor: pointer;
  transition: transform .18s cubic-bezier(.34,1.56,.64,1), box-shadow .18s;
}
.expert-card:hover { transform: translateY(-4px); box-shadow: 0 0 0 3px var(--ink); }
.expert-card.selected { box-shadow: 0 0 0 3px var(--hl), 0 0 0 5px var(--ink); }
.expert-portrait {
  display: block; width: 124px; height: 124px; flex: none;
  border-radius: 10px; background-color: #ecebe6; object-fit: cover;
  image-rendering: pixelated;
}
/* ================= 实现原理 ================= */
details summary { cursor: pointer; font-weight: 800; font-size: 15px; }
details summary:hover { color: var(--accent); }
details pre {
  margin-top: 14px; background: var(--ink); color: #f2ead8; padding: 18px 20px;
  border-radius: 14px; overflow: auto; font-size: 12.5px; line-height: 1.7;
  font-family: "SF Mono", Menlo, Consolas, monospace;
}

/* ================= 弹窗 ================= */
.modal {
  position: fixed; inset: 0; background: rgba(26,24,21,.5);
  display: none; align-items: center; justify-content: center; padding: 24px; z-index: 50;
}
.modal.open { display: flex; }
.modal-box {
  background: var(--card); border: 2px solid var(--line); border-radius: 20px;
  max-width: 600px; width: 100%; max-height: 88vh; overflow: auto; padding: 26px;
  box-shadow: 6px 6px 0 var(--ink);
}
.modal-top { display: flex; gap: 20px; align-items: flex-start; }
#modalPreview {
  width: 136px; height: 136px; flex: none;
  border: 2px solid var(--line); border-radius: 16px; background: #fff; padding: 8px;
  box-shadow: var(--hard-sm); display: flex; align-items: center; justify-content: center;
}
#modalPreview svg { width: 100%; height: 100%; }
#modalPreview .expert-detail { width: 124px; height: 124px; }
.modal-meta { font-size: 13px; color: var(--sub); line-height: 1.9; word-break: break-all; }
.modal-meta b { color: var(--ink); }
.modal-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
#modalCode {
  margin-top: 16px; background: var(--ink); color: #f2ead8; padding: 14px;
  border-radius: 12px; font-size: 11px; max-height: 220px; overflow: auto;
  font-family: "SF Mono", Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all;
}
@media (max-width: 700px) {
  .expert-grid { grid-template-columns: repeat(2, 124px); gap: 18px; }
}
@media (max-width: 560px) {
  body { padding: 20px 14px 64px; }
  .page-head { padding: 26px 20px 22px; }
  .page-head h1 { font-size: 28px; }
  .card { padding: 18px 16px; }
  #nameInput, #styleSelect { min-width: 100%; }
  .modal-top { flex-direction: column; }
}
@media (max-width: 300px) {
  .expert-grid { grid-template-columns: 124px; }
}

/* ================= 动效降级 ================= */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ================= 页脚 ================= */
.site-foot {
  margin-top: 40px; text-align: center; padding: 26px 20px 8px;
  border-top: 2px dashed rgba(26,24,21,.25); position: relative;
}
.site-foot .foot-doodle { position: absolute; top: -11px; left: 50%; transform: translateX(-50%); background: var(--bg); padding: 0 10px; line-height: 0; }
.site-foot p { font-size: 13.5px; font-weight: 800; letter-spacing: .5px; }
.site-foot .foot-sub { display: block; margin-top: 6px; font-size: 12px; color: var(--sub); font-weight: 600; }
