:root {
  --ink: #1d1b2f;
  --text: #3a3750;
  --muted: #6b6880;
  --line: #e9e6f2;
  --bg: #f6f5fb;
  --soft: #faf9fe;
  --brand: #785d88;
  --rainbow: linear-gradient(90deg, #9075a0, #3aa0ba 38%, #54b08b 68%, #e5c828);
  /* same hues, dark enough for text */
  --rainbow-text: linear-gradient(90deg, #785d88, #27788c 40%, #35785d 70%, #856400);
  /* darkening layer over --cd so white text stays readable on every group color */
  --shade: linear-gradient(160deg, transparent 30%, rgba(0, 0, 0, .18));
  --radius: 22px;
  --shadow: 0 12px 32px -16px rgba(45, 30, 110, .22);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Segoe UI", Roboto, sans-serif;
  /* group color, overridden per type */
  --c: #785d88;
  --cd: #594165;
  --cl: #f1edf3;
  --cs: #e3dde7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.65;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body:has(dialog[open]) { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(120, 93, 136, .5); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { display: block; width: 100%; height: auto; }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.wrap.wide { max-width: 1080px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: rgba(246, 245, 251, .84);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid rgba(233, 230, 242, .8);
}
.topbar-inner {
  max-width: 1080px; min-height: 56px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; font-weight: 800; font-size: 17px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.logo {
  flex: none; width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center;
  color: #fff; font-weight: 900; background: linear-gradient(135deg, #9075a0, #3aa0ba, #54b08b, #e5c828);
}
.tabs { flex: none; display: flex; background: #ebe8f5; border-radius: 999px; padding: 4px; }
.tabs button { min-height: 44px; padding: 0 14px; border-radius: 999px; font-size: 14px; font-weight: 600; color: #57546a; white-space: nowrap; transition: background .2s, color .2s; }
.tabs button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(40, 30, 90, .12); }

/* ---------- home ---------- */
.hero { position: relative; isolation: isolate; text-align: center; padding: 26px 16px 4px; overflow: hidden; }
.hero::before {
  content: ""; position: absolute; z-index: -1; left: -20%; right: -20%; top: -60px; bottom: 0;
  -webkit-mask-image: linear-gradient(#000 55%, transparent);
  mask-image: linear-gradient(#000 55%, transparent);
  background:
    radial-gradient(closest-side at 22% 55%, rgba(144, 117, 160, .24), transparent),
    radial-gradient(closest-side at 50% 30%, rgba(84, 176, 139, .16), transparent),
    radial-gradient(closest-side at 78% 55%, rgba(229, 200, 40, .22), transparent);
}
.hero-avatars { display: flex; justify-content: center; gap: 4px; max-width: 360px; margin: 0 auto 12px; }
.hero-avatars .float { width: 25%; animation: bob 3.2s ease-in-out infinite; }
.hero-avatars .float:nth-child(2) { animation-delay: .4s; }
.hero-avatars .float:nth-child(3) { animation-delay: .8s; }
.hero-avatars .float:nth-child(4) { animation-delay: 1.2s; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.hero h1 { font-size: clamp(28px, 7.4vw, 46px); line-height: 1.2; font-weight: 900; letter-spacing: .5px; }
.grad { background: var(--rainbow-text); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { max-width: 520px; margin: 12px auto 0; color: var(--muted); font-size: 15px; text-wrap: balance; }

.section-title { font-size: 18px; font-weight: 800; margin: 26px 0 12px; }
.set-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .set-grid { grid-template-columns: repeat(3, 1fr); } }
.set-card {
  position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: flex-start; text-align: left;
  padding: 16px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow);
  transition: transform .18s, box-shadow .18s;
}
.set-card::after { content: ""; position: absolute; right: -34px; top: -34px; width: 104px; height: 104px; border-radius: 50%; background: var(--sc); opacity: .1; }
@media (hover: hover) { .set-card:hover { transform: translateY(-3px); box-shadow: 0 18px 36px -18px rgba(45, 30, 110, .3); } }
.set-card:active { transform: scale(.98); }
.set-emoji {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 24px;
  background: linear-gradient(rgba(255, 255, 255, .84), rgba(255, 255, 255, .84)), var(--sc);
}
.set-name { margin-top: 12px; font-size: 18px; font-weight: 800; }
.set-age { font-size: 13px; color: var(--muted); }
.set-meta {
  margin-top: 10px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; color: var(--text);
  background: linear-gradient(rgba(255, 255, 255, .88), rgba(255, 255, 255, .88)), var(--sc);
}
.disclaimer { text-align: center; color: var(--muted); font-size: 12px; margin: 28px 0 40px; }

/* ---------- quiz ---------- */
.quiz-top { display: flex; align-items: center; gap: 12px; padding: 16px 0 12px; }
.icon-btn { flex: none; width: 44px; height: 44px; border-radius: 12px; background: #fff; border: 1px solid var(--line); font-size: 28px; line-height: 1; display: grid; place-items: center; padding-bottom: 3px; }
.progress { flex: 1; height: 10px; background: #e9e6f2; border-radius: 999px; overflow: hidden; }
.progress-bar { width: 0; height: 100%; border-radius: inherit; background: var(--rainbow); transition: width .3s ease; }
.progress-text { min-width: 52px; text-align: right; font-size: 14px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.q-card { background: #fff; border-radius: 26px; padding: 22px 18px 18px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.q-card.enter { animation: rise .32s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.q-tag { font-size: 13px; font-weight: 600; color: var(--muted); }
.q-text { margin: 8px 0 18px; font-size: 21px; line-height: 1.45; font-weight: 800; }
.options { display: grid; gap: 10px; }
.opt {
  min-height: 52px; padding: 14px 16px; border-radius: 16px; text-align: left; font-size: 16px; line-height: 1.5;
  background: var(--soft); border: 1.5px solid var(--line); transition: border-color .15s, background .15s, transform .15s;
}
@media (hover: hover) { .opt:hover { border-color: #b9a6c6; background: #f6f3f8; } }
.opt:active { transform: scale(.985); }
.opt.picked { border-color: var(--brand); background: #f1edf3; box-shadow: 0 0 0 3px rgba(120, 93, 136, .15); font-weight: 600; }
.quiz-hint { text-align: center; color: var(--muted); font-size: 13px; margin: 16px 0 40px; }
.big .q-text { font-size: 26px; }
.big .opt { font-size: 20px; padding: 18px; }
.big .q-tag, .big .progress-text, .big .quiz-hint { font-size: 16px; }

/* ---------- result ---------- */
#result { padding-bottom: 40px; }
.result-hero {
  position: relative; overflow: hidden; margin-top: 16px; padding: 22px 18px 24px; border-radius: 28px; text-align: center; color: var(--text);
  background: radial-gradient(circle at 50% 28%, rgba(255, 255, 255, .6), transparent 60%), var(--cs);
  box-shadow: var(--shadow);
}
.eyebrow { font-size: 13px; font-weight: 700; letter-spacing: .5px; color: var(--text); }
.hero-avatar { width: 168px; margin: 10px auto 0; padding: 8px; border-radius: 50%; background: rgba(255, 255, 255, .6); }
.pop { animation: pop .6s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop { from { opacity: 0; transform: scale(.6); } }
.you-are { margin-top: 8px; font-size: 14px; }
.nick { font-size: 44px; line-height: 1.15; font-weight: 900; letter-spacing: 2px; color: var(--cd); }
.code-line { margin-top: 4px; font-size: 15px; font-weight: 700; color: var(--ink); }
.tagline { max-width: 420px; margin: 10px auto 0; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 14px; }
.chips span { padding: 4px 12px; border-radius: 999px; background: rgba(255, 255, 255, .7); color: var(--cd); font-size: 13px; font-weight: 700; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.actions > :only-child { grid-column: 1 / -1; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 16px; border-radius: 14px;
  font-size: 15px; font-weight: 700; color: var(--ink); text-decoration: none; text-align: center;
  background: #fff; border: 1px solid var(--line); transition: transform .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { color: #fff; border: 0; background: var(--shade), var(--cd); box-shadow: 0 10px 20px -10px var(--cd); }
.btn.ghost { background: transparent; }

.card { margin-top: 14px; padding: 20px 18px; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow); }
.card h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 18px; font-weight: 800; }
.card h2::before { content: ""; flex: none; width: 6px; height: 18px; border-radius: 3px; background: var(--c); }
.lead { font-size: 15.5px; color: var(--text); }
.two-col { display: grid; gap: 10px; margin-top: 14px; }
@media (min-width: 560px) { .two-col { grid-template-columns: 1fr 1fr; } }
.pill-box { padding: 12px 14px; border-radius: 16px; }
.pill-box.good { background: var(--cl); }
.pill-box.warn { background: #fff3ef; }
.pill-box h3 { margin-bottom: 6px; font-size: 14px; }
.pill-box ul { padding-left: 18px; font-size: 14.5px; color: var(--text); }
.cartoon { margin-top: 14px; font-size: 14.5px; color: var(--muted); }
.cartoon b { color: var(--ink); }
.tips { list-style: none; counter-reset: tip; display: grid; gap: 10px; }
.tips li { counter-increment: tip; position: relative; padding: 12px 14px 12px 48px; border-radius: 14px; background: var(--soft); font-size: 15px; }
.tips li::before {
  content: counter(tip); position: absolute; left: 12px; top: 12px; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; background: var(--cd); color: #fff; font-size: 13px; font-weight: 800;
}
.match-head { width: 100%; display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding: 10px; border-radius: 18px; background: var(--cl); text-align: left; }
.mini-avatar { flex: none; width: 64px; }
.match-name { flex: 1; display: flex; flex-direction: column; }
.match-name b { font-size: 20px; color: var(--cd); }
.match-name small { font-size: 13px; font-weight: 600; color: var(--muted); }
.chev { font-size: 28px; color: var(--cd); }
.match p { font-size: 15px; color: var(--text); }
.stack { list-style: none; display: grid; gap: 12px; }
.stack li { display: flex; gap: 12px; align-items: flex-start; }
.stack em { flex: none; margin-top: 2px; padding: 3px 8px; border-radius: 8px; font-style: normal; font-size: 12px; font-weight: 800; color: var(--cd); background: var(--cl); }
.stack b { display: block; font-size: 15px; }
.stack span { font-size: 14px; color: var(--muted); }

/* one shared grid so the label column fits the longest label and all bars line up */
.bars { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px 10px; }
.bar-row { display: contents; }
.bar-label { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 14px; }
.bar-label b { min-width: 22px; }
.bar-label span { color: var(--muted); }
.bar-label em { flex: none; padding: 1px 6px; border-radius: 6px; font-style: normal; font-size: 11px; font-weight: 800; color: var(--cd); background: var(--cl); }
.bar { height: 12px; overflow: hidden; border-radius: 999px; background: #efeef2; }
.bar i { display: block; height: 100%; border-radius: inherit; background: #cdcbd5; transform-origin: left; animation: grow .8s ease; }
.strong .bar i { background: linear-gradient(90deg, var(--c), var(--cd)); }
@keyframes grow { from { transform: scaleX(0); } }
.bar-val { text-align: right; font-size: 13px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.energy { display: flex; align-items: center; gap: 12px; margin-top: 18px; font-size: 13px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.energy-track { position: relative; flex: 1; height: 10px; border-radius: 999px; background: linear-gradient(90deg, var(--cl), var(--cs)); }
.energy-track i {
  position: absolute; top: 50%; width: 20px; height: 20px; border-radius: 50%; transform: translate(-50%, -50%);
  background: #fff; border: 4px solid var(--c); box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.note { margin-top: 12px; font-size: 12.5px; color: var(--muted); }

/* ---------- gallery ---------- */
.page-head { padding: 28px 0 4px; text-align: center; }
.page-head h1 { font-size: clamp(26px, 6.4vw, 38px); font-weight: 900; }
.page-head p { margin-top: 6px; color: var(--muted); }
.group { margin-top: 26px; }
.group-head h2 { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 900; color: var(--cd); }
.group-head h2 i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 5px var(--cl); }
.group-head p { margin: 4px 0 12px; font-size: 14px; color: var(--muted); }
.type-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 760px) { .type-grid { grid-template-columns: repeat(4, 1fr); } }
.type-card {
  display: flex; flex-direction: column; align-items: center; padding: 14px 12px 16px; border-radius: var(--radius); text-align: center;
  background: linear-gradient(180deg, var(--cl), #fff 72%); border: 1px solid var(--line); box-shadow: var(--shadow); transition: transform .18s;
}
@media (hover: hover) { .type-card:hover { transform: translateY(-3px); } }
.type-card:active { transform: scale(.98); }
.tc-avatar { width: 96px; }
.type-card b { margin-top: 4px; font-size: 18px; font-weight: 900; color: var(--cd); }
.type-card small { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.type-card p {
  margin-top: 6px; font-size: 13px; color: #4a4760;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.funcs { margin-top: 30px; }
.func-grid { display: grid; gap: 10px; margin-top: 14px; }
@media (min-width: 560px) { .func-grid { grid-template-columns: 1fr 1fr; } }
.func { padding: 12px 14px; border-radius: 14px; background: var(--soft); border: 1px solid var(--line); }
.func b { display: inline-block; min-width: 34px; margin-right: 8px; padding: 1px 8px; border-radius: 8px; text-align: center; font-size: 13px; color: #fff; background: var(--ink); }
.func span { font-size: 14.5px; font-weight: 700; }
.func p { margin-top: 4px; font-size: 13.5px; color: var(--muted); }
#tab-types .actions { margin: 24px 0 48px; }

/* ---------- dialogs ---------- */
dialog { padding: 0; border: 0; color: var(--ink); background: transparent; max-width: none; max-height: none; }
dialog::backdrop { background: rgba(20, 16, 40, .5); }
.sheet {
  width: 100%; max-width: 640px; max-height: 90vh; margin: auto auto 0; overflow-y: auto; overscroll-behavior: contain;
  border-radius: 26px 26px 0 0; background: var(--bg);
}
.sheet[open] { animation: slide-up .3s ease; }
@keyframes slide-up { from { opacity: 0; transform: translateY(40px); } }
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 26px; max-height: 86vh; } }
.sheet-head { position: relative; padding: 22px 18px 20px; text-align: center; color: var(--text); background: radial-gradient(circle at 50% 30%, rgba(255, 255, 255, .6), transparent 60%), var(--cs); }
.sheet-avatar { width: 120px; margin: 0 auto; }
.sheet-head h2 { font-size: 32px; font-weight: 900; color: var(--cd); }
/* flow-root stops the first card's margin from collapsing into a gap that counts as backdrop */
.sheet-body { display: flow-root; padding: 0 14px calc(24px + env(safe-area-inset-bottom)); }
.close {
  position: absolute; top: 8px; right: 8px; z-index: 1; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 22px; line-height: 1; color: var(--ink); background: rgba(255, 255, 255, .7);
}
.share-dlg { width: min(92vw, 420px); max-height: 92vh; margin: auto; overflow-y: auto; }
.share-box { position: relative; display: grid; gap: 12px; padding: 18px; border-radius: 24px; text-align: center; background: #fff; }
.share-box .close { color: #fff; background: rgba(0, 0, 0, .45); }
.share-img { display: block; width: 100%; border-radius: 14px; box-shadow: var(--shadow); }
.share-hint { font-size: 14px; font-weight: 600; color: var(--muted); }
.share-status { padding: 60px 0; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
