/* Avatar Lab — styles */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --border: #e5e8ef;
  --border-strong: #d3d9e4;
  --text: #0f1320;
  --text-soft: #46506380;
  --muted: #5b6473;
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #eef0ff;
  --accent-grad: linear-gradient(180deg, #5b52ea, #4338ca);
  --ok: #16a34a;
  --code-bg: #0e1117;
  --code-text: #d7deea;
  --ring: 0 0 0 3px rgba(79, 70, 229, 0.18);
  --shadow-sm: 0 1px 2px rgba(15, 19, 32, 0.05);
  --shadow-md: 0 1px 2px rgba(15, 19, 32, 0.04), 0 14px 34px -16px rgba(15, 19, 32, 0.22);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --maxw: 1160px;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  --bg: #0a0c11;
  --surface: #12151d;
  --surface-2: #161a23;
  --border: #222834;
  --border-strong: #2e3543;
  --text: #f1f4f9;
  --text-soft: #c3cad680;
  --muted: #98a1b2;
  --accent: #8b8bfb;
  --accent-strong: #a5a5ff;
  --accent-soft: #1c1f33;
  --accent-grad: linear-gradient(180deg, #5a55cf, #3d3796);
  --code-bg: #05070b;
  --code-text: #cfd8e6;
  --ring: 0 0 0 3px rgba(139, 139, 251, 0.24);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 40px -20px rgba(0, 0, 0, 0.7);
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #0a0c11;
    --surface: #12151d;
    --surface-2: #161a23;
    --border: #222834;
    --border-strong: #2e3543;
    --text: #f1f4f9;
    --text-soft: #c3cad680;
    --muted: #98a1b2;
    --accent: #8b8bfb;
    --accent-strong: #a5a5ff;
    --accent-soft: #1c1f33;
    --code-bg: #05070b;
    --code-text: #cfd8e6;
    --ring: 0 0 0 3px rgba(139, 139, 251, 0.24);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.4), 0 18px 40px -20px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; }

h1, h2, h3 { margin: 0; letter-spacing: -0.02em; line-height: 1.15; }

code, pre { font-family: var(--mono); }

img { display: block; max-width: 100%; }

::selection { background: var(--accent); color: #fff; }

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-size: 16px;
}

.brand-mark { display: grid; place-items: center; }

.brand-name span { color: var(--accent); }

.nav {
  display: flex;
  gap: 4px;
  margin-left: 12px;
}

.nav a {
  padding: 7px 12px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav a:hover { color: var(--text); background: var(--surface); }

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
}

.seg-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn:hover { color: var(--text); }

.seg-btn[aria-pressed="true"] {
  background: var(--text);
  color: var(--bg);
}

.seg-wide { display: flex; }
.seg-wide .seg-btn { flex: 1; text-align: center; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover { transform: translateY(-1px); border-color: var(--border-strong); }

.icon-moon { display: none; }

html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .icon-sun { display: none; }
  html:not([data-theme="light"]) .icon-moon { display: block; }
}

/* ---------- layout ---------- */

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 28px 80px;
}

/* ---------- hero ---------- */

.hero {
  padding: 72px 0 40px;
  text-align: center;
}

.hero-badges {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 22px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
  box-shadow: var(--shadow-sm);
}

.chip::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent);
}

.hero h1 {
  font-size: clamp(2.1rem, 5.2vw, 3.5rem);
  font-weight: 680;
  letter-spacing: -0.035em;
  max-width: 18ch;
  margin: 0 auto;
  text-wrap: balance;
}

.lede {
  max-width: 56ch;
  margin: 18px auto 0;
  color: var(--muted);
  font-size: 16px;
  text-wrap: pretty;
}

.hero-faces {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 34px;
}

.hero-faces img {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  border: 3px solid var(--bg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

/* ---------- cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

/* ---------- playground ---------- */

.playground {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  gap: 22px;
  align-items: start;
  margin-top: 26px;
}

.stage {
  position: sticky;
  top: 88px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.stage-media {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: 340px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background:
    radial-gradient(120% 120% at 20% 0%, color-mix(in srgb, var(--accent) 8%, transparent), transparent 60%),
    var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
}

#preview {
  width: 78%;
  height: 78%;
  object-fit: contain;
  border-radius: 14px;
  transition: opacity 0.18s ease;
  opacity: 0;
}

#preview.is-ready { opacity: 1; }

.spinner {
  position: absolute;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 2.5px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.spinner.is-on { opacity: 1; }

@keyframes spin { to { transform: rotate(360deg); } }

.stage-caption {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.stage-caption code {
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12.5px;
}

html[data-theme="dark"] .stage-caption code { color: var(--accent); }

.stage-actions {
  display: flex;
  gap: 10px;
  width: 100%;
}

/* ---------- buttons ---------- */

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}

/* ---------- controls ---------- */

.controls {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.field { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.field label,
.field-head label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.field-hint { font-size: 12px; color: var(--muted); }

.field-note { font-size: 11.5px; color: var(--muted); }

.field-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.field.is-disabled { opacity: 0.45; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
}

.input-group {
  display: flex;
  gap: 8px;
}

input[type="text"] {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.ghost-btn {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.ghost-btn:hover { color: var(--text); border-color: var(--accent); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: var(--border);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 17px;
  height: 17px;
  margin-top: -6px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: var(--shadow-sm);
}

input[type="range"]::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: var(--border);
}

input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  background: var(--surface);
  border: 2px solid var(--accent);
}

input[type="range"]:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 999px; }

input[type="range"]:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- swatches ---------- */

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.swatch {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--swatch, #fff);
  cursor: pointer;
  padding: 0;
  position: relative;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.swatch:hover { transform: scale(1.08); }

.swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent);
}

.swatch.is-none {
  background: repeating-linear-gradient(45deg, var(--surface-2) 0 4px, var(--border) 4px 8px);
}

.swatch-custom {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px dashed var(--border-strong);
  background: var(--surface-2);
  padding: 0;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.swatch-custom input {
  position: absolute;
  inset: -6px;
  width: 150%;
  height: 150%;
  border: 0;
  padding: 0;
  background: none;
  cursor: pointer;
  opacity: 0;
}

/* ---------- style grid ---------- */

.style-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  gap: 8px;
  max-height: 236px;
  overflow-y: auto;
  padding: 2px;
  scrollbar-width: thin;
}

.style-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 7px 4px 5px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease, background 0.15s ease;
}

.style-item:hover { transform: translateY(-1px); border-color: var(--border-strong); }

.style-item[aria-checked="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.style-item img {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: var(--surface);
}

.style-item span {
  font-size: 10.5px;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.style-item[aria-checked="true"] span { color: var(--accent-strong); }

html[data-theme="dark"] .style-item[aria-checked="true"] span { color: var(--accent); }

/* ---------- switch ---------- */

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.switch input { position: absolute; opacity: 0; pointer-events: none; }

.switch-track {
  width: 40px;
  height: 23px;
  flex: none;
  border-radius: 999px;
  background: var(--border-strong);
  padding: 2px;
  transition: background 0.18s ease;
}

.switch-thumb {
  display: block;
  width: 19px;
  height: 19px;
  border-radius: 999px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform 0.18s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(17px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }

.switch-label { font-size: 13.5px; color: var(--text); }

/* ---------- sections ---------- */

.api, .styles { margin-top: 78px; }

.section-head { margin-bottom: 20px; }

.section-head h2 {
  font-size: clamp(1.4rem, 2.4vw, 1.85rem);
  font-weight: 660;
}

.section-head p {
  margin: 8px 0 0;
  color: var(--muted);
  max-width: 62ch;
}

/* ---------- code ---------- */

.code-card { overflow: hidden; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  padding: 8px 12px 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover { color: var(--text); }

.tab.is-active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.code-body { position: relative; background: var(--code-bg); }

.code-body pre {
  margin: 0;
  padding: 20px 20px 20px;
  overflow-x: auto;
  min-height: 92px;
}

.code-body code {
  font-size: 13px;
  line-height: 1.65;
  color: var(--code-text);
  white-space: pre-wrap;
  word-break: break-all;
}

.copy-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  height: 30px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid #2a3140;
  background: #171c26;
  color: #c9d3e3;
  font: inherit;
  font-size: 12px;
  font-weight: 550;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.copy-btn:hover { background: #202634; color: #fff; }

.code-foot {
  padding: 11px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- facts ---------- */

.facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.fact {
  padding: 20px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
}

.fact h3 { font-size: 14.5px; font-weight: 600; margin-bottom: 6px; }

.fact p { margin: 0; font-size: 13.5px; color: var(--muted); }

/* ---------- gallery ---------- */

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 12px;
}

.gallery-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 18px 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.14s ease, border-color 0.15s ease, box-shadow 0.18s ease;
}

.gallery-item:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.gallery-item img {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  background: var(--surface-2);
}

.gallery-item span {
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding: 26px 28px 40px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.site-footer p { margin: 0; }

.site-footer a { color: var(--text); text-decoration-color: var(--border-strong); }

.dot { margin: 0 8px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 14px);
  padding: 10px 18px;
  border-radius: 999px;
  background: #10131a;
  color: #f4f6fa;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 80;
}

html[data-theme="dark"] .toast { background: #e9edf5; color: #0b0d12; }

.toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- focus ---------- */

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- responsive ---------- */

@media (max-width: 980px) {
  .playground { grid-template-columns: 1fr; }
  .stage { position: static; }
  .stage-media { max-width: 300px; }
  .facts { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .site-header { padding: 12px 16px; gap: 10px; flex-wrap: wrap; }
  .nav { margin-left: 0; order: 3; width: 100%; }
  main { padding: 0 16px 64px; }
  .hero { padding: 44px 0 28px; }
  .field-row { grid-template-columns: 1fr; }
  .hero-faces img { width: 60px; height: 60px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
