/* Character Atelier. Type scale: 12 / 13 / 14 / 16 px. Body text keeps at least 4.5:1 contrast on cards. */
:root {
  color-scheme: light;
  --paper: #f5f3ee;
  --card: #fffefa;
  --sunken: #f6f4ee;
  --ink: #222526;
  --ink-2: #454a49;
  --muted: #656a69;
  --line: #e8e5dd;
  --line-strong: #d8d4c9;
  --accent: #6f67c7;
  --accent-dark: #5149a9;
  --accent-soft: #efedfb;
  --accent-line: #c9c5ee;
  --coral: #ed9a7e;
  --amber-bg: #faf3df;
  --amber-ink: #7a5a1f;
  --danger: #a44f3a;
  --ok: #3f8062;
  --shadow: 0 16px 40px rgba(49, 48, 42, .07);
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs: 14px;
  --fs-lg: 16px;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); font-size: var(--fs); line-height: 1.6; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid #aaa5ec; outline-offset: 2px; }
a { color: inherit; }
.language-toggle { position: fixed; z-index: 1200; top: 14px; right: 18px; min-height: 34px; border: 1px solid var(--line-strong); border-radius: 99px; padding: 0 13px; color: var(--ink-2); background: rgba(255,254,250,.96); box-shadow: 0 3px 12px rgba(49,48,42,.08); font-size: var(--fs-xs); font-weight: 650; }
.language-toggle:hover { color: var(--accent-dark); border-color: var(--accent-line); background: white; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin: 7px 0 0; font-family: Georgia, "Microsoft YaHei", serif; font-size: clamp(26px, 3vw, 34px); font-weight: 500; letter-spacing: -.6px; line-height: 1.25; text-wrap: balance; }
.eyebrow { color: var(--accent); font-size: var(--fs-xs); font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-xs); }
.mt-12 { margin-top: 12px; }

/* ---------- shell ---------- */
.app-shell { min-height: 100vh; display: grid; grid-template-columns: 256px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 16px 20px; display: flex; flex-direction: column; background: #fbfaf7; border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 10px 28px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 14px; color: white; background: var(--accent); font-size: 22px; transform: rotate(-7deg); }
.brand-title { font-family: Georgia, "Microsoft YaHei", serif; font-size: 19px; letter-spacing: -.4px; }
.brand-caption { margin-top: 2px; color: var(--muted); font-size: var(--fs-xs); letter-spacing: 1px; text-transform: uppercase; }
.nav-label { margin: 10px 12px 8px; color: var(--muted); font-size: var(--fs-xs); letter-spacing: 1.2px; }
.nav-list { display: grid; gap: 4px; scrollbar-width: none; }
.nav-list::-webkit-scrollbar { display: none; }
.nav-item { border: 0; border-radius: 12px; padding: 11px 13px; display: flex; align-items: center; gap: 12px; color: var(--ink-2); background: transparent; text-align: left; font-size: var(--fs); transition: background .18s, color .18s; }
.nav-item:hover { color: var(--ink); background: #f2f0e9; }
.nav-item.active { color: var(--accent-dark); background: var(--accent-soft); font-weight: 650; }
.nav-icon { width: 20px; text-align: center; font-size: 17px; }
.sidebar-bottom { margin-top: auto; }
.phase-card { padding: 15px; border: 1px solid #e7e2d8; border-radius: 15px; background: #f7f4eb; }
.phase-card .eyebrow { color: #86633a; }
.phase-card p { margin: 8px 0 10px; color: var(--ink-2); font-size: var(--fs-xs); line-height: 1.65; }
.phase-link { border: 0; padding: 0; color: var(--accent-dark); background: transparent; font-size: var(--fs-xs); font-weight: 700; }
.user-row { margin-top: 16px; padding: 13px 8px 0; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: #594d90; background: #dedaf4; font-size: var(--fs-sm); font-weight: 700; }
.user-email { min-width: 0; flex: 1; overflow: hidden; color: var(--ink-2); font-size: var(--fs-xs); text-overflow: ellipsis; white-space: nowrap; }
.logout-button { border: 0; color: var(--muted); background: transparent; font-size: var(--fs-xs); }
.main { min-width: 0; padding: 0 40px 64px; }
.topbar { min-height: 72px; padding-right: 92px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.crumb { color: var(--muted); font-size: var(--fs-sm); }
.top-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.provider-pill { display: flex; align-items: center; gap: 7px; border: 1px solid #e7e4dc; border-radius: 99px; padding: 6px 12px; color: var(--ink-2); background: #fbfaf7; font-size: var(--fs-xs); }
.provider-dot { width: 8px; height: 8px; border-radius: 50%; background: #d3a95f; }
.provider-dot.on { background: var(--ok); }
.content { max-width: 1280px; margin: 0 auto; padding-top: 34px; }
.page-heading { margin-bottom: 22px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.heading-copy { max-width: 620px; margin: 8px 0 0; color: var(--muted); font-size: var(--fs); line-height: 1.7; text-wrap: pretty; }

/* ---------- controls ---------- */
.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; padding: 0 16px; color: white; background: var(--accent); font-size: var(--fs); font-weight: 650; text-decoration: none; transition: background .15s, transform .15s, border-color .15s; }
.button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.button.secondary { border-color: var(--line-strong); color: var(--ink-2); background: var(--card); }
.button.secondary:hover { border-color: var(--accent-line); color: var(--accent-dark); background: #faf9ff; }
.button.ghost { color: var(--accent-dark); background: transparent; }
.button.ghost:hover { background: var(--accent-soft); }
.button.danger { border-color: #f0d1c8; color: var(--danger); background: #fff8f5; }
.button.danger:hover { background: #fdece5; }
.button.compact { min-height: 32px; padding: 0 12px; border-radius: 8px; font-size: var(--fs-sm); }
.button.danger-text { color: var(--danger); }
.button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.field { min-width: 0; display: grid; gap: 7px; }
.field.full { grid-column: 1 / -1; }
.field label, .field-label { color: var(--ink-2); font-size: var(--fs-sm); font-weight: 650; }
.field label span { color: var(--muted); font-weight: 400; }
.field input, .field textarea, .field select, .char-pick select { width: 100%; border: 1px solid var(--line-strong); border-radius: 10px; padding: 10px 12px; color: var(--ink); background: #fffefb; font-size: var(--fs); }
select { appearance: none; padding-right: 34px !important; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23656a69' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.field textarea { min-height: 84px; resize: vertical; line-height: 1.65; }
.field input::placeholder, .field textarea::placeholder { color: #838785; }
.field-help { color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.checkline { display: grid; grid-template-columns: 18px minmax(0, 1fr); gap: 10px; align-items: start; color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.65; }
.checkline input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); }
.link { border: 0; padding: 0; color: var(--accent-dark); background: none; font: inherit; text-decoration: underline; text-underline-offset: 2px; }
.pill { padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); background: var(--sunken); font-size: var(--fs-xs); white-space: nowrap; }
.pill.edited, .pill.blocked, .pill.queued { border-color: #ecdcae; color: var(--amber-ink); background: var(--amber-bg); }
.pill.optimized, .pill.succeeded { border-color: var(--accent-line); color: var(--accent-dark); background: var(--accent-soft); }
.pill.failed { border-color: #f0d1c8; color: var(--danger); background: #fff3ee; }

/* ---------- panels, banners, lists ---------- */
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--card); box-shadow: 0 8px 24px rgba(49, 48, 42, .025); }
.form-panel { padding: 24px; }
.banner { margin: 16px 0; padding: 14px 16px; border: 1px solid #e9dfc8; border-radius: 12px; display: flex; align-items: flex-start; gap: 10px; color: #62583f; background: #faf6e9; font-size: var(--fs-sm); line-height: 1.7; }
.banner.info { border-color: #e2dff4; color: #514d74; background: #f5f3fc; }
.banner-icon { flex: 0 0 auto; font-size: 16px; }
.stats-grid { margin: 22px 0 28px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.stat-card { padding: 17px 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.stat-label { color: var(--muted); font-size: var(--fs-sm); }
.stat-value { margin-top: 8px; font-family: Georgia, serif; font-size: 26px; line-height: 1.2; }
.stat-note { margin-top: 4px; color: var(--muted); font-size: var(--fs-xs); }
.section-head { margin: 26px 0 12px; display: flex; align-items: center; justify-content: space-between; }
.section-head h2 { margin: 0; font-family: Georgia, "Microsoft YaHei", serif; font-size: 18px; font-weight: 500; }
.section-head span { color: var(--muted); font-size: var(--fs-sm); }
.character-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.character-card { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--card); cursor: pointer; transition: box-shadow .2s, transform .2s; }
.character-card:hover { box-shadow: var(--shadow); transform: translateY(-3px); }
.character-art { position: relative; height: 196px; overflow: hidden; display: grid; place-items: center; background: #ebe9f4; }
.character-art.color-1 { background: #e9eee8; }
.character-art.color-2 { background: #f5e9de; }
.character-art.color-3 { background: #e5edf1; }
.character-art img { width: 100%; height: 100%; object-fit: cover; }
.avatar-art { width: 112px; height: 112px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.75); border-radius: 50%; color: #554c96; background: rgba(255,255,255,.66); font-family: Georgia, serif; font-size: 42px; box-shadow: 0 10px 24px rgba(49,48,42,.08); }
.avatar-mini { width: 100%; height: 100%; display: grid; place-items: center; color: #554c96; background: linear-gradient(145deg, #eae8f5, #f8f0e7); font-family: Georgia, serif; font-size: 26px; }
.status-tag { position: absolute; top: 12px; left: 12px; border: 1px solid rgba(255,255,255,.75); border-radius: 99px; padding: 4px 10px; color: var(--ink-2); background: rgba(255,255,255,.86); backdrop-filter: blur(8px); font-size: var(--fs-xs); }
.character-info { padding: 15px 16px 16px; }
.character-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.character-title { overflow: hidden; font-size: var(--fs-lg); font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.character-date { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }
.character-subtitle { min-height: 20px; margin: 6px 0 12px; overflow: hidden; color: var(--muted); font-size: var(--fs-sm); text-overflow: ellipsis; white-space: nowrap; }
.tag-row { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { border-radius: 6px; padding: 4px 8px; color: #5f5a86; background: #f1eff9; font-size: var(--fs-xs); }
.empty-state { padding: 56px 24px; border: 1px dashed #d9d6cf; border-radius: 16px; background: rgba(255,254,250,.7); text-align: center; }
.empty-illustration { width: 66px; height: 66px; margin: 0 auto 15px; display: grid; place-items: center; border-radius: 24px; color: var(--accent-dark); background: var(--accent-soft); font-size: 27px; }
.empty-state h2 { margin-bottom: 8px; font-family: Georgia, serif; font-size: 21px; font-weight: 500; }
.empty-state p { max-width: 460px; margin: 0 auto 18px; color: var(--muted); font-size: var(--fs); line-height: 1.75; }
.quota-bar { margin-bottom: 20px; padding: 12px 15px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: var(--card); font-size: var(--fs-sm); line-height: 1.8; }

/* ---------- create + edit ---------- */
.mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.mode-option { position: relative; min-height: 124px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; color: var(--ink); background: var(--card); text-align: left; }
.mode-option:hover { border-color: var(--accent-line); }
.mode-option.selected { border-color: #aca7e4; background: #f7f6fe; box-shadow: inset 0 0 0 1px var(--accent-line); }
.mode-option strong { font-size: var(--fs); }
.mode-option small { color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.mode-icon { color: var(--accent-dark); font-size: 20px; }
.form-grid { margin-top: 22px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 14px; }
.upload-zone { padding: 17px; border: 1px dashed #c3bedf; border-radius: 12px; display: flex; align-items: center; gap: 14px; color: var(--accent-dark); background: #faf9ff; cursor: pointer; }
.upload-zone:hover { border-color: #928bd5; background: #f6f4ff; }
.upload-zone input { display: none; }
.upload-zone strong { display: block; color: #48455f; font-size: var(--fs-sm); }
.upload-zone small { display: block; margin-top: 3px; color: var(--muted); font-size: var(--fs-xs); }
.upload-zone .upload-icon { font-size: 22px; }
.upload-preview { width: 60px; height: 60px; border-radius: 10px; object-fit: cover; }
.form-actions { margin-top: 20px; padding-top: 17px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form-error { color: #aa3c35; font-size: var(--fs-sm); line-height: 1.6; }

/* ---------- character detail ---------- */
.detail-layout { display: grid; grid-template-columns: minmax(260px, .8fr) minmax(0, 1.2fr); gap: 20px; }
.detail-portrait { position: relative; min-height: 340px; overflow: hidden; border-radius: 16px; display: grid; place-items: center; background: #ebe9f4; }
.detail-portrait img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.detail-portrait .avatar-art { width: 142px; height: 142px; font-size: 58px; }
.detail-card { padding: 22px; }
.detail-title { margin: 6px 0 8px; font-family: Georgia, "Microsoft YaHei", serif; font-size: 28px; font-weight: 500; }
.detail-description { color: var(--muted); font-size: var(--fs); line-height: 1.75; white-space: pre-wrap; }
.detail-actions { margin: 16px 0 20px; display: flex; flex-wrap: wrap; gap: 8px; }
.detail-divider { margin: 20px 0; border: 0; border-top: 1px solid var(--line); }
.attribute-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.attribute { padding: 11px 13px; border-radius: 10px; background: var(--sunken); }
.attribute span { display: block; color: var(--muted); font-size: var(--fs-xs); }
.attribute strong { display: block; margin-top: 4px; color: var(--ink-2); font-size: var(--fs); font-weight: 600; }
.generation-list { display: grid; gap: 8px; }
.generation-row { padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); font-size: var(--fs-sm); }
.generation-row small { display: block; margin-top: 3px; color: var(--muted); }

/* ---------- template library ---------- */
.template-toolbar { margin: 20px 0 14px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip { min-height: 34px; border: 1px solid var(--line-strong); border-radius: 99px; padding: 0 14px; color: var(--ink-2); background: var(--card); font-size: var(--fs-sm); }
.filter-chip.active { border-color: var(--accent); color: white; background: var(--accent); }
.template-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.template-card { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.template-preview { height: 138px; margin-bottom: 12px; border-radius: 10px; display: grid; place-items: center; background: #f1eff8; }
.template-card:nth-child(3n+2) .template-preview { background: #eff3ed; }
.template-card:nth-child(3n) .template-preview { background: #f8f0e8; }
.template-preview svg { width: 76px; height: 112px; overflow: visible; }
.template-preview .face-glyph { color: #675fb3; font-family: Georgia, serif; font-size: 62px; }
.template-preview .face-svg { width: 88px; height: 88px; }
.template-meta { color: var(--muted); font-size: var(--fs-xs); }
.template-name { margin: 4px 0 5px; font-size: var(--fs); font-weight: 700; }
.template-desc { margin: 0; color: var(--muted); font-size: var(--fs-sm); line-height: 1.6; }

/* ---------- studio ---------- */
.studio { display: grid; grid-template-columns: minmax(340px, 480px) minmax(0, 1fr); gap: 24px; align-items: start; }
.studio-main { display: grid; gap: 14px; min-width: 0; }
.studio-side { position: sticky; top: 16px; display: grid; gap: 14px; min-width: 0; }
.step { padding: 18px 18px 20px; }
.step-head { margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.step-head h2 { margin: 0; display: flex; align-items: center; gap: 10px; font-size: var(--fs-lg); }
.step-no { width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 50%; color: var(--accent-dark); background: var(--accent-soft); font-size: var(--fs-xs); font-weight: 700; }
.group-label { margin: 18px 0 8px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; color: var(--ink-2); font-size: var(--fs-sm); font-weight: 650; }
.step-head + .group-label, .step-head + .char-pick { margin-top: 0; }
.group-label span { color: var(--muted); font-size: var(--fs-xs); font-weight: 400; text-align: right; }
.char-pick { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 14px; align-items: center; }
.char-thumb { width: 64px; height: 64px; overflow: hidden; border-radius: 12px; }
.char-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.char-pick-body { min-width: 0; display: grid; gap: 6px; }
.char-pick-body small { color: var(--muted); font-size: var(--fs-xs); }
.tile-grid { display: grid; gap: 8px; }
.pose-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.face-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.tile { padding: 8px 4px 7px; border: 1px solid var(--line); border-radius: 12px; display: grid; justify-items: center; gap: 4px; color: var(--ink-2); background: var(--card); transition: border-color .15s, background .15s; }
.tile:hover { border-color: var(--accent-line); background: #faf9ff; }
.tile.selected { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent-line); font-weight: 650; }
.tile-art { width: 100%; aspect-ratio: 1 / 1.05; padding: 4px 8px; display: grid; place-items: center; }
.tile-art svg { width: 100%; height: 100%; overflow: visible; }
.tile-name { font-size: var(--fs-xs); line-height: 1.35; text-align: center; }
.face-svg .face, .face-svg path, .face-svg ellipse, .face-svg circle:not(.dot) { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.face-svg .dot { fill: var(--accent); stroke: none; }
.face-svg .blush { stroke: var(--coral); stroke-width: 2.4; }
.face-svg .tear { stroke: #79aed6; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 34px; padding: 0 13px; border: 1px solid var(--line-strong); border-radius: 99px; display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); background: var(--card); font-size: var(--fs-sm); transition: border-color .15s, background .15s; }
.chip:hover:not(:disabled) { border-color: var(--accent-line); background: #faf9ff; }
.chip.selected { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-soft); font-weight: 650; }
.chip:disabled { cursor: not-allowed; opacity: .42; }
.ratio-icon { width: 18px; height: 18px; flex: none; }
.ratio-icon rect { fill: none; stroke: currentColor; stroke-width: 1.6; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 12px; background: var(--sunken); }
.segmented .chip { border-color: transparent; border-radius: 9px; background: transparent; }
.segmented .chip.selected { border-color: transparent; background: var(--card); box-shadow: 0 1px 3px rgba(34, 37, 38, .12); }
.prompt-tools { min-height: 32px; margin: -4px 0 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.prompt-text { width: 100%; min-height: 200px; resize: vertical; border: 1px solid var(--line-strong); border-radius: 12px; padding: 12px 14px; color: var(--ink); background: #fffefb; font-size: var(--fs); line-height: 1.75; }
.prompt-text.is-busy { opacity: .6; background: linear-gradient(110deg, #fffefb 30%, #f0eefb 50%, #fffefb 70%) 0 0 / 200% 100%; animation: shimmer 1.4s linear infinite; }
.prompt-foot { margin-top: 6px; display: flex; justify-content: space-between; gap: 12px; }
.prompt-foot .field-help:last-child { white-space: nowrap; }
.advanced { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line-strong); }
.advanced summary { color: var(--ink-2); font-size: var(--fs-sm); cursor: pointer; }
.advanced .field { margin-top: 12px; }
.studio-bar { position: sticky; bottom: 12px; z-index: 5; padding: 12px 14px 12px 16px; border: 1px solid var(--line-strong); border-radius: 16px; background: rgba(255, 254, 250, .95); backdrop-filter: blur(10px); box-shadow: 0 10px 30px rgba(49, 48, 42, .14); }
.bar-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.bar-summary { min-width: 0; display: grid; }
.bar-summary strong { overflow: hidden; font-size: var(--fs); text-overflow: ellipsis; white-space: nowrap; }
.bar-summary span { overflow: hidden; color: var(--muted); font-size: var(--fs-xs); text-overflow: ellipsis; white-space: nowrap; }
.primary-cta { min-height: 46px; flex: none; padding: 0 26px; font-size: var(--fs-lg); }
.bar-note { margin: 0; padding: 0 6px; color: var(--muted); font-size: var(--fs-xs); line-height: 1.7; }

/* stage */
.stage { --frame-h: clamp(320px, calc(100vh - 300px), 720px); display: grid; justify-items: center; gap: 12px; }
.stage-frame { position: relative; width: min(100%, calc(var(--frame-h) * var(--ratio-n, .75))); aspect-ratio: var(--ratio, 3 / 4); overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--sunken); box-shadow: var(--shadow); }
.stage-frame.idle { display: grid; place-items: center; background: linear-gradient(160deg, #eeecf8, #f7efe6); }
.idle-backdrop { position: absolute; inset: 0; }
.idle-backdrop img { width: 100%; height: 100%; object-fit: cover; filter: blur(18px) saturate(.9); opacity: .32; transform: scale(1.12); }
.idle-figure { position: relative; width: 36%; max-width: 170px; }
.idle-figure svg { width: 100%; height: auto; overflow: visible; }
.idle-copy { position: absolute; right: 0; bottom: 20px; left: 0; padding: 0 18px; display: grid; gap: 2px; text-align: center; }
.idle-copy strong { font-size: var(--fs-lg); }
.idle-copy span { color: var(--muted); font-size: var(--fs-sm); }
.stage-frame.busy { display: grid; place-items: center; background: #efedf7; }
.shimmer { position: absolute; inset: 0; background: linear-gradient(110deg, transparent 20%, rgba(255, 255, 255, .7) 45%, transparent 70%) 0 0 / 200% 100%; animation: shimmer 1.6s linear infinite; }
.busy-info { position: relative; padding: 0 22px; display: grid; justify-items: center; gap: 8px; text-align: center; }
.busy-info strong { font-size: var(--fs-lg); }
.busy-info span { color: var(--ink-2); font-size: var(--fs-sm); }
.busy-info small { max-width: 300px; color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.spinner { width: 30px; height: 30px; border: 3px solid var(--accent-line); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
.stage-image { position: absolute; inset: 0; padding: 0; border: 0; display: block; background: var(--sunken); cursor: zoom-in; }
.stage-image img { width: 100%; height: 100%; object-fit: contain; display: block; }
.ai-tag { position: absolute; top: 10px; left: 10px; padding: 3px 10px; border-radius: 99px; color: white; background: rgba(34, 37, 38, .74); font-size: var(--fs-xs); pointer-events: none; }
.stage-frame.failed, .stage-frame.plan { display: grid; place-items: center; background: #f8f3ef; }
.stage-note { max-width: 300px; padding: 0 20px; display: grid; gap: 6px; text-align: center; }
.stage-note strong { font-size: var(--fs-lg); }
.stage-note span { color: var(--muted); font-size: var(--fs-sm); line-height: 1.7; }
.stage-frame.failed .stage-note strong { color: var(--danger); }
.stage-meta { display: grid; gap: 2px; text-align: center; }
.stage-meta strong { font-size: var(--fs-lg); }
.stage-meta span { color: var(--muted); font-size: var(--fs-xs); }
.stage-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.history { width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--card); }
.history-head { margin-bottom: 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.history-head h3 { margin: 0; font-size: var(--fs); }
.history-head h3 span, .history-head > span { color: var(--muted); font-size: var(--fs-xs); font-weight: 400; }
.quota-warn { color: var(--danger); font-weight: 650; }
.thumb-strip { display: flex; gap: 8px; padding-bottom: 4px; overflow-x: auto; }
.thumb { position: relative; width: 64px; height: 86px; flex: 0 0 auto; padding: 0; overflow: hidden; border: 2px solid transparent; border-radius: 10px; background: var(--sunken); }
.thumb:hover { border-color: var(--accent-line); }
.thumb.selected { border-color: var(--accent); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-state { height: 100%; display: grid; place-items: center; color: var(--muted); font-size: var(--fs-xs); }
.thumb-state.failed { color: var(--danger); }

/* gallery on the character card */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery-item { position: relative; aspect-ratio: 3 / 4; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--sunken); text-align: left; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.gallery-item:hover img { transform: scale(1.03); }
.gallery-cap { position: absolute; right: 0; bottom: 0; left: 0; padding: 26px 10px 9px; display: grid; color: white; background: linear-gradient(transparent, rgba(0, 0, 0, .6)); }
.gallery-cap b { font-size: var(--fs-sm); font-weight: 650; }
.gallery-cap small { font-size: var(--fs-xs); opacity: .88; }
.gallery-item .ai-tag { top: 8px; left: 8px; padding: 2px 8px; }
.gallery-item.plain { aspect-ratio: auto; padding: 12px; display: grid; align-content: start; gap: 6px; background: var(--card); }
.gallery-item.plain b { font-size: var(--fs-sm); }
.gallery-item.plain small { color: var(--muted); font-size: var(--fs-xs); line-height: 1.6; }
.gallery-item.plain .pill { justify-self: start; }

/* modal + lightbox */
.modal-backdrop { position: fixed; inset: 0; z-index: 40; padding: 24px; display: grid; place-items: center; overflow: auto; background: rgba(34, 37, 38, .5); backdrop-filter: blur(3px); animation: fade .16s ease-out; }
.modal { position: relative; width: min(100%, 470px); max-height: 100%; padding: 26px; overflow: auto; border-radius: 20px; background: var(--card); box-shadow: 0 30px 80px rgba(0, 0, 0, .3); animation: rise .18s ease-out; }
.modal.wide { width: min(100%, 940px); padding: 14px; }
.modal h2 { margin: 6px 0 12px; font-family: Georgia, "Microsoft YaHei", serif; font-size: 22px; font-weight: 500; }
.modal-note { margin: 12px 0 0; color: var(--muted); font-size: var(--fs-sm); line-height: 1.7; }
.modal-actions { margin-top: 20px; display: flex; justify-content: flex-end; gap: 8px; }
.consent-list { margin: 0; padding-left: 20px; display: grid; gap: 10px; color: var(--ink-2); font-size: var(--fs); line-height: 1.7; }
.modal-x { position: absolute; top: 10px; right: 10px; z-index: 2; width: 36px; height: 36px; border: 0; border-radius: 50%; color: white; background: rgba(34, 37, 38, .62); font-size: 22px; line-height: 1; }
.modal-x:hover { background: rgba(34, 37, 38, .82); }
.lightbox-image { display: grid; place-items: center; overflow: hidden; border-radius: 12px; background: var(--sunken); }
.lightbox-image img { max-width: 100%; max-height: 74vh; object-fit: contain; display: block; }
.lightbox-bar { margin-top: 12px; padding: 0 6px 4px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.lightbox-bar h2 { margin: 0; font-size: 18px; }
.lightbox-bar span { color: var(--muted); font-size: var(--fs-xs); }
.lightbox-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.share-link-box { margin: 14px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; display: flex; align-items: center; gap: 8px; background: #fbfaf6; }
.share-link-box input { min-width: 0; flex: 1; border: 0; outline: 0; color: var(--ink-2); background: transparent; font-size: var(--fs-sm); }

/* ---------- auth + share pages ---------- */
.auth-wrap, .share-wrap { min-height: 100vh; padding: 64px 25px 25px; display: grid; place-items: center; background: radial-gradient(ellipse at 12% 20%, #e6e2f6 0, transparent 35%), radial-gradient(ellipse at 92% 82%, #e7eee4 0, transparent 34%), var(--paper); }
.auth-card { width: min(100%, 430px); padding: 34px; border: 1px solid rgba(230, 227, 219, .9); border-radius: 20px; background: rgba(255, 254, 250, .92); box-shadow: 0 25px 75px rgba(56, 53, 72, .1); }
.auth-card .brand { padding: 0 0 24px; }
.auth-card h1 { font-size: 28px; }
.auth-card > p { margin: 10px 0 22px; color: var(--muted); font-size: var(--fs); line-height: 1.7; }
.auth-card .field + .field { margin-top: 14px; }
.auth-submit { width: 100%; margin-top: 17px; }
.auth-switch { margin-top: 16px; color: var(--muted); font-size: var(--fs-sm); text-align: center; }
.auth-switch button { border: 0; color: var(--accent-dark); background: transparent; font-weight: 650; }
.notice-small { margin-top: 12px; color: var(--muted); font-size: var(--fs-xs); line-height: 1.65; }
.recovery-code { padding: 18px; overflow-wrap: anywhere; white-space: pre-wrap; border-radius: 10px; background: var(--accent-soft); font-size: var(--fs-lg); line-height: 1.8; user-select: all; }
.terms-card { width: min(100%, 780px); padding: 28px; line-height: 1.8; }
.terms-text { white-space: pre-wrap; font-size: var(--fs); }
.share-card { width: min(100%, 800px); overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--card); box-shadow: var(--shadow); }
.share-head { padding: 19px 23px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.share-head .brand { padding: 0; }
.share-body { padding: 23px; display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 22px; }
.share-portrait { min-height: 290px; overflow: hidden; border-radius: 14px; display: grid; place-items: center; background: #efedf7; }
.share-portrait img { width: 100%; height: 100%; min-height: 290px; object-fit: cover; }
.share-footer { padding: 14px 23px; border-top: 1px solid var(--line); color: var(--muted); font-size: var(--fs-xs); }
.badge-blocked { border-radius: 99px; padding: 4px 10px; color: var(--amber-ink); background: var(--amber-bg); font-size: var(--fs-xs); white-space: nowrap; }

/* ---------- feedback ---------- */
.toast { position: fixed; z-index: 60; left: 50%; bottom: 24px; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 10px; color: white; background: #323638; box-shadow: 0 8px 22px rgba(0, 0, 0, .2); font-size: var(--fs-sm); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
button:disabled { cursor: not-allowed; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.985); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; } }

/* ---------- responsive ---------- */
@media (max-width: 1240px) {
  .studio { grid-template-columns: 1fr; }
  .studio-side { position: static; }
  .stage { --frame-h: min(70vh, 640px); }
}
@media (max-width: 1040px) {
  .main { padding-right: 24px; padding-left: 24px; }
  .character-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .template-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 13px 14px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 0 3px 12px; }
  .nav-label, .sidebar-bottom { display: none; }
  .nav-list { display: flex; gap: 5px; padding-bottom: 11px; overflow-x: auto; }
  .nav-item { flex: 0 0 auto; padding: 9px 12px; }
  .nav-icon { font-size: 15px; }
  .main { padding: 0 16px 48px; }
  .topbar { min-height: 52px; padding: 8px 74px 8px 0; }
  .crumb { display: none; }
  .top-actions { width: 100%; justify-content: flex-start; }
  .provider-pill { padding: 4px 10px; }
  .content { padding-top: 24px; }
  .stats-grid { gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 22px; }
  .character-grid { gap: 10px; }
  .character-art { height: 150px; }
  .character-info { padding: 12px; }
  .detail-layout { grid-template-columns: 1fr; }
  .detail-portrait { min-height: 260px; }
  .template-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .share-body { grid-template-columns: 1fr; }
  .share-portrait { min-height: 240px; }
  .pose-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .face-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage { --frame-h: min(62vh, 560px); }
  .modal-backdrop { padding: 12px; }
}
@media (max-width: 440px) {
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading > .button { align-self: stretch; }
  .character-grid { grid-template-columns: 1fr; }
  .character-art { height: 200px; }
  .mode-grid { grid-template-columns: 1fr; }
  .mode-option { min-height: auto; display: grid; grid-template-columns: 26px 1fr; }
  .mode-option small { grid-column: 2; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .form-panel { padding: 16px; }
  .step { padding: 16px 14px 18px; }
  .pose-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-note { display: none; }
  .bar-row { gap: 10px; }
  .primary-cta { padding: 0 18px; }
  .modal { padding: 20px; }
}
@media print {
  .language-toggle { display: none !important; }
  body { background: white; }
  .sidebar, .topbar, .detail-actions, .page-heading > .button, .banner, .toast, .gallery-cap, .ai-tag { display: none !important; }
  .app-shell { display: block; }
  .main { padding: 0; }
  .content { max-width: none; padding: 0; }
  .detail-layout { grid-template-columns: 34% 1fr; }
  .panel, .detail-portrait { break-inside: avoid; box-shadow: none; }
  .detail-portrait { min-height: 270px; }
  .character-grid { grid-template-columns: repeat(3, 1fr); }
}

.visitor-actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 24px 0; }
.share-card:has(.visitor-actions) { width: min(1100px, 100%); }
.share-card:has(.visitor-actions) .share-portrait { display: grid; place-content: center; text-align: center; padding: 24px; }
