:root {
  color-scheme: dark;
  --night-950: #0d0a11;
  --night-900: #15111b;
  --night-850: #1b1622;
  --night-800: #231c2b;
  --night-700: #34283e;
  --paper: #f7f1e9;
  --paper-deep: #e9dfd3;
  --ink: #211a25;
  --white: #fffaf4;
  --muted-light: #b7aebc;
  --muted-dark: #746a79;
  --gold: #d8b77c;
  --gold-soft: #f0d7a8;
  --rose: #cc6b85;
  --plum: #795080;
  --success: #74b99a;
  --danger: #d45f71;
  --line-dark: rgba(255, 250, 244, .12);
  --line-light: rgba(47, 34, 49, .13);
  --shadow-soft: 0 18px 60px rgba(4, 2, 7, .2);
  --shadow-deep: 0 36px 100px rgba(4, 2, 7, .42);
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-lg: 28px;
  --radius-xl: 40px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --app-height: 100dvh;
  --app-top: 0px;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
html {
  background: var(--night-950);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
body {
  margin: 0;
  color: var(--white);
  background:
    radial-gradient(circle at 15% -10%, rgba(123, 76, 133, .24), transparent 34%),
    var(--night-950);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button, input, textarea { -webkit-tap-highlight-color: transparent; }
img { display: block; max-width: 100%; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid rgba(240, 215, 168, .72);
  outline-offset: 3px;
}

.view {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  min-height: 100dvh;
}
.app-container {
  width: min(100% - 32px, 1220px);
  margin-inline: auto;
}
.ambient {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  opacity: .34;
  filter: blur(90px);
  pointer-events: none;
}
.ambient-one {
  width: 340px;
  height: 340px;
  top: 8%;
  left: -220px;
  background: #9c557c;
}
.ambient-two {
  width: 280px;
  height: 280px;
  right: -180px;
  bottom: 4%;
  background: #594b9c;
}

.kicker, .step-label {
  margin: 0 0 var(--space-2);
  color: var(--gold);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  text-transform: uppercase;
}
.button {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 20px;
  color: var(--white);
  background: transparent;
  font-weight: 700;
  transition: transform .18s ease, border-color .18s ease, background .18s ease;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0) scale(.985); }
.button:disabled { cursor: wait; opacity: .55; }
.button-primary {
  border-color: rgba(247, 226, 182, .22);
  color: #241820;
  background: linear-gradient(135deg, #f0d7a8, #c98d71);
  box-shadow: 0 12px 34px rgba(206, 145, 113, .22);
}
.button-secondary {
  border-color: var(--line-dark);
  background: rgba(255, 250, 244, .06);
}
.button-wide { width: 100%; }
.icon-button {
  min-width: 46px;
  min-height: 46px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line-dark);
  border-radius: 999px;
  color: inherit;
  background: rgba(255,255,255,.04);
  font-size: 19px;
}
.text-button {
  min-height: 44px;
  border: 0;
  padding: 8px 0;
  color: var(--gold-soft);
  background: transparent;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--white);
}
.brand-seal {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid rgba(240, 215, 168, .48);
  border-radius: 15px 15px 15px 4px;
  color: var(--gold-soft);
  background: rgba(255,255,255,.055);
  font: 700 20px/1 "Songti SC", STSong, serif;
}
.brand-lockup strong, .brand-lockup small { display: block; }
.brand-lockup strong {
  font: 700 17px/1.25 "Songti SC", STSong, serif;
  letter-spacing: .12em;
}
.brand-lockup small {
  margin-top: 3px;
  color: var(--muted-light);
  font-size: 8px;
  letter-spacing: .18em;
}

/* Auth */
.auth-view { display: grid; place-items: center; padding: var(--space-4); }
.auth-layout {
  width: min(1180px, 100%);
  min-height: min(760px, calc(100dvh - 32px));
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, .75fr);
  overflow: hidden;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-xl);
  background: var(--night-850);
  box-shadow: var(--shadow-deep);
}
.auth-story {
  position: relative;
  min-height: 680px;
  overflow: hidden;
  padding: 38px 42px;
  background:
    linear-gradient(110deg, rgba(19,14,24,.94) 4%, rgba(24,17,29,.54) 48%, transparent 75%),
    radial-gradient(circle at 76% 32%, rgba(197, 120, 139, .18), transparent 35%),
    #19131f;
}
.auth-story::before {
  content: "";
  position: absolute;
  width: 470px;
  height: 470px;
  right: -74px;
  top: 64px;
  border: 1px solid rgba(240, 215, 168, .24);
  border-radius: 50%;
  box-shadow: inset 0 0 80px rgba(240, 215, 168, .06);
}
.auth-copy {
  position: relative;
  z-index: 4;
  max-width: 460px;
  margin-top: 94px;
}
.auth-copy h1 {
  margin: 0;
  font: 700 clamp(38px, 5vw, 64px)/1.15 "Songti SC", STSong, serif;
  letter-spacing: .03em;
}
.auth-copy > p:last-child {
  width: min(410px, 92%);
  margin: 22px 0 0;
  color: #c9bfca;
  font-size: 16px;
}
.auth-portraits {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
}
.auth-portrait {
  position: absolute;
  overflow: hidden;
  margin: 0;
  border: 1px solid rgba(240, 215, 168, .2);
  background: #211827;
  box-shadow: var(--shadow-deep);
}
.auth-portrait img { width: 100%; height: 100%; object-fit: cover; }
.auth-portrait-main {
  width: 330px;
  height: 525px;
  right: 25px;
  bottom: -40px;
  border-radius: 170px 170px 28px 28px;
}
.auth-portrait-main img { object-position: 50% 18%; }
.auth-portrait-side {
  width: 190px;
  height: 300px;
  right: 286px;
  bottom: -38px;
  border-radius: 100px 100px 22px 22px;
  opacity: .7;
}
.auth-portrait-side img { object-position: 48% 20%; }
.auth-proof {
  position: absolute;
  z-index: 5;
  left: 42px;
  bottom: 30px;
  display: flex;
  gap: 18px;
  color: #bfb4c1;
  font-size: 11px;
}
.auth-proof span::before { content: "◇"; margin-right: 6px; color: var(--gold); }
.auth-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 46px;
  background:
    radial-gradient(circle at 100% 0, rgba(121, 80, 128, .2), transparent 28%),
    #f5eee6;
  color: var(--ink);
}
.release-stamp {
  position: absolute;
  top: 26px;
  right: 28px;
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid #cdbbc6;
  border-radius: var(--radius-pill);
  color: #75576a;
  background: rgb(255 255 255 / .52);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
}
.mobile-brand { display: none; }
.space-badge {
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  border-radius: 999px;
  padding: 7px 11px;
  color: #6c5168;
  background: #e7dbe4;
  font-size: 11px;
  font-weight: 700;
}
.space-badge span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(116,185,154,.15);
}
.auth-panel h2 {
  margin: 0;
  font: 700 30px/1.28 "Songti SC", STSong, serif;
}
.panel-lead { margin: 10px 0 12px; color: var(--muted-dark); }
.field { display: grid; gap: 7px; margin-top: 16px; }
.field label, .personality-fieldset legend {
  color: #433947;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
}
.field input {
  width: 100%;
  min-height: 50px;
  border: 1px solid rgba(46, 32, 48, .15);
  border-radius: 14px;
  padding: 11px 14px;
  color: var(--ink);
  background: rgba(255,255,255,.72);
  transition: border-color .18s ease, box-shadow .18s ease;
}
.field input:focus {
  border-color: #a57687;
  outline: 0;
  box-shadow: 0 0 0 4px rgba(165,118,135,.13);
}
.auth-panel .button-wide { margin-top: 22px; }
.trust-note {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  margin-top: 22px;
  border-top: 1px solid var(--line-light);
  padding-top: 18px;
  color: var(--muted-dark);
  font-size: 12px;
}
.trust-note span { color: var(--plum); }
.trust-note p { margin: 0; }
.auth-panel .text-button { align-self: flex-start; color: #6f4c66; font-size: 12px; }
.form-error {
  margin: 12px 0 0;
  border: 1px solid rgba(174,72,88,.22);
  border-radius: 12px;
  padding: 9px 11px;
  color: #983a4b;
  background: #fff0f2;
  font-size: 12px;
}

/* Home */
.home-view {
  padding-bottom: calc(108px + var(--safe-bottom));
  background:
    radial-gradient(circle at 80% 8%, rgba(145,83,126,.15), transparent 24%),
    linear-gradient(180deg, #15111b 0, #100d15 70%);
}
.topbar {
  min-height: calc(86px + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--safe-top);
}
.account-switcher {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-dark);
  border-radius: 999px;
  padding: 7px 9px 7px 8px;
  color: var(--white);
  background: rgba(255,255,255,.04);
}
.account-orb {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, #f5deb1, transparent 18%),
    linear-gradient(145deg, #b36b87, #56416d);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.account-copy { min-width: 100px; text-align: left; }
.account-copy small, .account-copy strong { display: block; }
.account-copy small { color: var(--muted-light); font-size: 9px; }
.account-copy strong { overflow: hidden; max-width: 120px; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.switch-label {
  border-left: 1px solid var(--line-dark);
  padding: 4px 7px 4px 10px;
  color: var(--gold-soft);
  font-size: 11px;
}
.home-content { padding-top: 44px; }
.home-hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 28px;
  border-bottom: 1px solid var(--line-dark);
  padding-bottom: 30px;
}
.home-hero h1 {
  margin: 0;
  font: 700 clamp(28px, 5vw, 48px)/1.2 "Songti SC", STSong, serif;
}
.home-hero p:last-child { margin: 12px 0 0; color: var(--muted-light); }
.hero-stat {
  min-width: 128px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: end;
  column-gap: 9px;
}
.hero-stat strong { color: var(--gold-soft); font: 600 50px/1 Georgia, serif; }
.hero-stat > span { padding-bottom: 6px; color: var(--white); }
.hero-stat small { grid-column: 1 / -1; margin-top: 4px; color: var(--muted-light); text-align: right; }
.group-entry {
  width: 100%;
  min-height: 118px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 22px;
  margin-top: 28px;
  overflow: hidden;
  border: 1px solid rgba(240,215,168,.18);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
  color: var(--white);
  text-align: left;
  background:
    radial-gradient(circle at 95% 10%, rgba(207,118,142,.22), transparent 32%),
    linear-gradient(135deg, rgba(120,74,112,.3), rgba(37,28,45,.9));
  box-shadow: var(--shadow-soft);
}
.group-faces { display: flex; padding-left: 10px; }
.group-faces img {
  width: 66px;
  height: 66px;
  margin-left: -10px;
  border: 2px solid #292030;
  border-radius: 50%;
  object-fit: cover;
  object-position: 50% 18%;
  background: #2d2334;
}
.group-copy small, .group-copy strong, .group-copy span { display: block; }
.group-copy small { color: var(--gold-soft); font-size: 10px; letter-spacing: .08em; }
.group-copy strong { margin: 3px 0; font: 700 22px/1.3 "Songti SC", STSong, serif; }
.group-copy span { color: var(--muted-light); font-size: 12px; }
.round-arrow {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 50%;
  color: var(--gold-soft);
  background: rgba(255,255,255,.05);
  font-size: 20px;
}
.characters-section { margin-top: 56px; }
.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}
.section-heading h2, .section-heading h3 { margin: 0; font: 700 27px/1.25 "Songti SC", STSong, serif; }
.section-heading.compact { align-items: center; margin-bottom: 16px; }
.section-heading.compact p:last-child { max-width: 260px; margin: 0; color: var(--muted-light); font-size: 12px; text-align: right; }
.portrait-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.portrait-skeleton {
  min-height: 390px;
  border-radius: var(--radius-lg);
  background: linear-gradient(100deg, #211a28 20%, #2d2334 45%, #211a28 70%);
  background-size: 220% 100%;
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer { to { background-position: -220% 0; } }
.persona-card {
  position: relative;
  min-height: 405px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: var(--radius-lg);
  padding: 0;
  color: var(--white);
  text-align: left;
  background: #211926;
  box-shadow: 0 16px 44px rgba(2,1,4,.22);
  transition: transform .22s ease, border-color .22s ease;
}
.persona-card:hover { transform: translateY(-5px); border-color: rgba(240,215,168,.4); }
.persona-card > img {
  width: 100%;
  height: 100%;
  min-height: 405px;
  object-fit: cover;
  object-position: 50% 18%;
  transition: transform .35s ease;
}
.persona-card:hover > img { transform: scale(1.025); }
.persona-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: end;
  padding: 72px 18px 18px;
  background: linear-gradient(180deg, transparent 36%, rgba(13,10,17,.22) 54%, rgba(13,10,17,.96) 100%);
}
.persona-topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.persona-topline h3 { margin: 0; font: 700 23px/1.2 "Songti SC", STSong, serif; }
.role-chip {
  width: fit-content;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--gold-soft);
  background: rgba(15,11,18,.4);
  font-size: 10px;
  backdrop-filter: blur(8px);
}
.persona-preview {
  overflow: hidden;
  margin-top: 7px;
  color: #c5bcc8;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.persona-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; color: #a99fab; font-size: 10px; }
.persona-foot span:last-child { color: var(--gold-soft); }
.discover {
  display: grid;
  grid-template-columns: minmax(220px, .58fr) minmax(0, 1.42fr);
  gap: 40px;
  align-items: center;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  padding: 28px;
  background: rgba(255,255,255,.025);
}
.discover-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  margin-bottom: 24px;
  border: 1px solid rgba(240,215,168,.38);
  border-radius: 50%;
  color: var(--gold-soft);
  font: 700 17px/1 "Songti SC", STSong, serif;
}
.discover h3 { margin: 0; font: 700 28px/1.25 "Songti SC", STSong, serif; }
.discover-copy > p:last-child { color: var(--muted-light); }
.role-preview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}
.role-preview {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.11);
  border-radius: 18px;
  padding: 0;
  color: var(--white);
  background: #241b2a;
}
.role-preview img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.role-preview span {
  position: absolute;
  inset: auto 8px 8px;
  border-radius: 999px;
  padding: 5px 8px;
  color: var(--white);
  background: rgba(12,8,15,.66);
  font-size: 11px;
  backdrop-filter: blur(7px);
}
.floating-create {
  position: fixed;
  z-index: 20;
  right: max(18px, calc((100vw - 1220px) / 2));
  bottom: calc(20px + var(--safe-bottom));
  box-shadow: 0 18px 42px rgba(0,0,0,.36);
}

/* Create */
.create-view {
  padding-bottom: 54px;
  background:
    radial-gradient(circle at 74% 22%, rgba(125,79,125,.17), transparent 27%),
    var(--night-950);
}
.create-topbar {
  min-height: calc(106px + var(--safe-top));
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 16px;
  padding-top: var(--safe-top);
  border-bottom: 1px solid var(--line-dark);
}
.create-topbar h1 { margin: 0; font: 700 24px/1.3 "Songti SC", STSong, serif; }
.step-badge { color: var(--gold); font: 600 14px/1 Georgia, serif; letter-spacing: .14em; }
.create-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, .55fr);
  gap: 28px;
  padding-top: 36px;
}
.role-picker { min-width: 0; }
.role-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.role-card {
  position: relative;
  min-height: 275px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 22px;
  padding: 0;
  color: var(--white);
  background: #211927;
}
.role-card[aria-pressed="true"] {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(216,183,124,.2), 0 20px 40px rgba(0,0,0,.28);
}
.role-card img { width: 100%; height: 275px; object-fit: cover; object-position: 50% 18%; }
.role-card-copy {
  position: absolute;
  inset: auto 0 0;
  padding: 52px 12px 12px;
  text-align: left;
  background: linear-gradient(transparent, rgba(12,9,15,.93));
}
.role-card-copy strong, .role-card-copy small { display: block; }
.role-card-copy strong { font: 700 18px/1.2 "Songti SC", STSong, serif; }
.role-card-copy small { margin-top: 3px; color: #c0b6c2; font-size: 9px; letter-spacing: .08em; }
.role-check {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 26px;
  height: 26px;
  display: none;
  place-items: center;
  border-radius: 50%;
  color: #211820;
  background: var(--gold-soft);
  font-size: 13px;
}
.role-card[aria-pressed="true"] .role-check { display: grid; }
.selected-role-stage {
  --role-accent: #795080;
  position: relative;
  min-height: 562px;
  grid-row: 1 / span 2;
  grid-column: 2;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 30px;
  background: var(--night-800);
  box-shadow: var(--shadow-deep);
}
[data-accent="blue"] { --role-accent: #3d6ea7; }
[data-accent="rose"] { --role-accent: #ae526e; }
[data-accent="red"] { --role-accent: #9d4b58; }
[data-accent="coral"] { --role-accent: #b8645b; }
[data-accent="green"] { --role-accent: #58775a; }
[data-accent="teal"] { --role-accent: #4c7877; }
[data-accent="navy"] { --role-accent: #374d70; }
[data-accent="plum"] { --role-accent: #795080; }
.selected-role-stage::before, .companion-stage::before {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  background: linear-gradient(145deg, transparent 50%, color-mix(in srgb, var(--role-accent), transparent 35%));
  pointer-events: none;
}
.selected-role-stage img { width: 100%; height: 100%; min-height: 562px; object-fit: cover; object-position: 50% 18%; }
.stage-vignette {
  position: absolute;
  z-index: 2;
  inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(11,8,14,.2) 57%, rgba(11,8,14,.94) 100%);
  pointer-events: none;
}
.stage-copy {
  position: absolute;
  z-index: 3;
  inset: auto 24px 24px;
}
.stage-copy p { margin: 0 0 5px; color: var(--gold-soft); font-size: 9px; letter-spacing: .18em; }
.stage-copy h2 { margin: 0; font: 700 32px/1.2 "Songti SC", STSong, serif; }
.stage-copy span { display: block; margin-top: 8px; color: #d4cad5; font-size: 12px; }
.persona-form-card {
  grid-column: 1;
  border: 1px solid var(--line-dark);
  border-radius: 28px;
  padding: 24px;
  color: var(--ink);
  background: var(--paper);
}
.personality-fieldset { min-width: 0; margin: 0; border: 0; padding: 0; }
.personality-fieldset legend { margin-bottom: 10px; }
.personality-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
.personality-choice {
  min-height: 72px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--line-light);
  border-radius: 15px;
  padding: 10px 12px;
  color: var(--ink);
  text-align: left;
  background: rgba(255,255,255,.55);
}
.personality-choice[aria-pressed="true"] {
  border-color: #8f657e;
  background: #eadfe7;
  box-shadow: 0 0 0 3px rgba(143,101,126,.1);
}
.personality-choice strong { font-size: 13px; }
.personality-choice small { overflow: hidden; margin-top: 3px; color: var(--muted-dark); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { margin: 10px 0 0; color: var(--muted-dark); font-size: 11px; }
.persona-form-card .button-wide { margin-top: 20px; }

/* Chat */
.chat-view {
  height: 100vh;
  height: var(--app-height);
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
}
.chat-shell {
  width: 100%;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(360px, 33vw, 480px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}
.companion-stage {
  --role-accent: #795080;
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: var(--night-850);
}
.companion-stage > img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; }
.stage-back {
  position: absolute;
  z-index: 5;
  top: calc(22px + var(--safe-top));
  left: 22px;
  min-height: 44px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--white);
  background: rgba(12,9,15,.48);
  backdrop-filter: blur(12px);
}
.companion-meta {
  position: absolute;
  z-index: 4;
  inset: auto 30px calc(34px + var(--safe-bottom));
}
.companion-meta h1 { margin: 10px 0 5px; font: 700 clamp(32px, 4vw, 50px)/1.1 "Songti SC", STSong, serif; }
.companion-meta p { margin: 0; color: #d2c8d3; }
.conversation-panel {
  --thread-width: 820px;
  --thread-gutter: max(24px, calc((100% - var(--thread-width)) / 2));
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background:
    radial-gradient(circle at 70% -10%, rgba(203,151,137,.14), transparent 28%),
    var(--paper);
}
.conversation-header {
  min-height: calc(88px + var(--safe-top));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: var(--safe-top) var(--thread-gutter) 0;
  border-bottom: 1px solid var(--line-light);
}
.conversation-header .icon-button { display: none; border-color: var(--line-light); }
.mobile-chat-avatar { display: none; }
.conversation-heading { min-width: 0; }
.conversation-header strong, .conversation-header small { display: block; }
.conversation-header strong {
  overflow: hidden;
  font-family: "Songti SC", STSong, serif;
  font-size: 20px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-header small {
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted-dark);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.online-status {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  border: 1px solid rgba(116,185,154,.22);
  border-radius: 999px;
  padding: 7px 12px;
  color: #537765;
  background: rgba(255,255,255,.52);
  font-size: 11px;
  white-space: nowrap;
}
.online-status i {
  width: 9px;
  height: 9px;
  display: block;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(116,185,154,.14);
}
.chat-scroll {
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;
  padding: 22px var(--thread-gutter) 30px;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}
.ai-disclosure {
  width: fit-content;
  max-width: 94%;
  margin: 0 auto 26px;
  border: 1px solid var(--line-light);
  border-radius: 999px;
  padding: 6px 11px;
  color: var(--muted-dark);
  background: rgba(255,255,255,.46);
  font-size: 10px;
  text-align: center;
}
.message { display: flex; align-items: flex-end; gap: 10px; margin: 10px 0; }
.message.user { justify-content: flex-end; }
.mini-avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border: 1px solid rgba(50,35,50,.13);
  border-radius: 13px;
  object-fit: cover;
  object-position: 50% 18%;
  background: #dfd4d9;
}
.message-body { max-width: min(72%, 640px); }
.speaker { margin: 0 0 4px 4px; color: var(--muted-dark); font-size: 10px; }
.bubble {
  border: 1px solid var(--line-light);
  border-radius: 7px 19px 19px;
  padding: 11px 14px;
  color: var(--ink);
  background: rgba(255,255,255,.86);
  box-shadow: 0 5px 18px rgba(55,38,55,.06);
  overflow-wrap: anywhere;
  line-height: 1.6;
  white-space: pre-wrap;
  user-select: text;
}
.user .bubble {
  border: 0;
  border-radius: 19px 7px 19px 19px;
  color: var(--white);
  background: linear-gradient(135deg, #57405f, #8b586d);
}
.thinking .bubble { color: var(--muted-dark); }
.thinking-dot { display: inline-block; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.chat-error {
  width: fit-content;
  margin: 14px auto;
  border: 1px solid rgba(184,76,93,.25);
  border-radius: 14px;
  padding: 10px 12px;
  color: #8c3747;
  background: #fff0f1;
  font-size: 12px;
  text-align: center;
}
.chat-error button {
  min-height: 38px;
  margin-left: 7px;
  border: 0;
  color: #7d3042;
  background: transparent;
  font-weight: 700;
  text-decoration: underline;
}
.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
  padding: 13px var(--thread-gutter) calc(13px + var(--safe-bottom));
  border-top: 1px solid var(--line-light);
  background: rgba(247,241,233,.9);
  backdrop-filter: blur(18px);
}
.composer-field {
  position: relative;
  min-width: 0;
}
.composer textarea {
  width: 100%;
  min-width: 0;
  min-height: 62px;
  max-height: 142px;
  display: block;
  resize: none;
  overflow-y: auto;
  border: 1px solid var(--line-light);
  border-radius: 18px;
  padding: 12px 15px 28px;
  color: var(--ink);
  background: rgba(255,255,255,.72);
  line-height: 1.5;
}
.composer textarea:focus { border-color: #92677f; outline: 0; box-shadow: 0 0 0 4px rgba(146,103,127,.12); }
.composer-hint {
  position: absolute;
  right: 14px;
  bottom: 8px;
  color: #958992;
  font-size: 9px;
  pointer-events: none;
}
.send-button {
  min-width: 98px;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 0;
  border-radius: 17px;
  color: var(--white);
  background: linear-gradient(135deg, #57405f, #966076);
  font-weight: 700;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease;
}
.send-button:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(87,64,95,.18); }
.send-button:active:not(:disabled) { transform: translateY(0); }
.send-button:focus-visible { outline: 3px solid rgba(146,103,127,.24); outline-offset: 3px; }
.send-button:disabled { cursor: wait; opacity: .55; }
.group-portrait-collage {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 2px;
  background: var(--night-850);
}
.group-portrait-collage img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 18%; filter: saturate(.88); }
.group-portrait-collage[data-count="2"] { grid-template-rows: 1fr; }
.group-portrait-collage[data-count="3"] img:first-child { grid-row: 1 / span 2; }
.group-portrait-collage::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(16,12,19,.18);
}

/* Feedback */
#toast {
  position: fixed;
  z-index: 100;
  top: calc(18px + var(--safe-top));
  left: 50%;
  max-width: calc(100% - 32px);
  transform: translate(-50%, -14px);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px;
  padding: 10px 15px;
  color: var(--white);
  background: rgba(25,18,29,.94);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
dialog {
  width: min(calc(100% - 32px), 520px);
  border: 1px solid var(--line-light);
  border-radius: 26px;
  padding: 28px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: var(--shadow-deep);
}
dialog::backdrop { background: rgba(7,5,9,.72); backdrop-filter: blur(6px); }
.dialog-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--gold);
  background: var(--night-850);
}
dialog h2 { margin: 14px 0 8px; font: 700 24px/1.3 "Songti SC", STSong, serif; }
dialog p, dialog li { color: var(--muted-dark); }
dialog .button-secondary { border-color: var(--line-light); color: var(--ink); background: rgba(65,46,66,.07); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .auth-layout { grid-template-columns: 1.05fr .95fr; }
  .auth-story { padding: 30px; }
  .auth-copy { margin-top: 72px; }
  .auth-portrait-main { right: -74px; opacity: .72; }
  .auth-portrait-side { display: none; }
  .auth-proof { left: 30px; flex-direction: column; gap: 5px; }
  .portrait-grid { grid-template-columns: repeat(3, 1fr); }
  .discover { grid-template-columns: 1fr; }
  .role-preview-grid { grid-template-columns: repeat(8, minmax(110px, 1fr)); overflow-x: auto; padding-bottom: 8px; }
  .create-layout { grid-template-columns: 1fr 260px; }
  .role-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 720px), (max-width: 920px) and (max-height: 500px) {
  .app-container { width: min(100% - 28px, 1220px); }
  .auth-view { display: block; padding: 0; }
  .auth-layout {
    min-height: 100vh;
    min-height: 100dvh;
    display: block;
    border: 0;
    border-radius: 0;
    background: var(--night-900);
  }
  .auth-story {
    min-height: 288px;
    padding: calc(22px + var(--safe-top)) 22px 20px;
    background:
      linear-gradient(180deg, rgba(18,13,22,.06), #17111c 96%),
      #17111c;
  }
  .auth-story > .brand-lockup, .auth-copy > p:last-child, .auth-proof { display: none; }
  .auth-copy { position: absolute; z-index: 5; left: 22px; bottom: 24px; max-width: 270px; margin: 0; }
  .auth-copy .kicker { margin-bottom: 4px; }
  .auth-copy h1 { font-size: 31px; }
  .auth-story::before { width: 250px; height: 250px; top: 8px; right: -44px; }
  .auth-portrait-main {
    width: 205px;
    height: 307px;
    right: -8px;
    bottom: -44px;
    border-radius: 110px 110px 0 0;
    opacity: .82;
  }
  .auth-panel { min-height: calc(100dvh - 288px); padding: 26px 22px calc(28px + var(--safe-bottom)); border-radius: 26px 26px 0 0; }
  .release-stamp { top: 31px; right: 22px; }
  .mobile-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
  .mobile-brand .brand-seal { width: 38px; height: 38px; color: #6c455e; border-color: #c7a6b6; background: #eadce4; }
  .mobile-brand strong { font: 700 18px/1 "Songti SC", STSong, serif; letter-spacing: .08em; }
  .auth-panel h2 { font-size: 26px; }
  .panel-lead { font-size: 12px; }
  .space-badge { display: none; }
  .topbar { min-height: calc(74px + var(--safe-top)); }
  .topbar .brand-lockup small { display: none; }
  .account-copy { min-width: 76px; }
  .account-copy strong { max-width: 88px; }
  .switch-label { display: none; }
  .home-content { padding-top: 30px; }
  .home-hero { align-items: start; }
  .home-hero h1 { font-size: 29px; }
  .home-hero p:last-child { font-size: 12px; }
  .hero-stat { min-width: 74px; display: block; text-align: right; }
  .hero-stat strong { display: block; font-size: 38px; }
  .hero-stat > span { display: block; padding: 0; font-size: 11px; }
  .hero-stat small { font-size: 9px; }
  .group-entry { min-height: 102px; gap: 14px; padding: 14px; }
  .group-faces img { width: 48px; height: 48px; }
  .group-copy strong { font-size: 18px; }
  .round-arrow { width: 42px; height: 42px; }
  .characters-section { margin-top: 38px; }
  .section-heading { align-items: center; }
  .section-heading h2 { font-size: 23px; }
  .section-heading .button-secondary { display: none; }
  .portrait-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .portrait-skeleton { min-height: 280px; }
  .persona-card, .persona-card > img { min-height: 300px; }
  .persona-overlay { padding: 58px 12px 13px; }
  .persona-topline { display: block; }
  .persona-topline h3 { font-size: 20px; }
  .persona-topline .role-chip { margin-top: 5px; }
  .persona-preview { font-size: 11px; }
  .discover { gap: 24px; padding: 20px; }
  .discover-mark { margin-bottom: 16px; }
  .discover h3 { font-size: 24px; }
  .role-preview-grid { margin-inline: -20px; padding-inline: 20px; grid-template-columns: repeat(8, 126px); }
  .floating-create { right: 14px; bottom: calc(14px + var(--safe-bottom)); }
  .create-topbar {
    min-height: calc(88px + var(--safe-top));
    grid-template-columns: 48px 1fr;
  }
  .create-topbar h1 { font-size: 18px; }
  .create-topbar .step-badge { display: none; }
  .create-layout { display: flex; flex-direction: column; padding-top: 24px; }
  .role-grid {
    grid-template-columns: repeat(8, 138px);
    overflow-x: auto;
    margin-inline: -14px;
    padding: 2px 14px 10px;
    scroll-snap-type: x mandatory;
  }
  .role-card { min-height: 230px; scroll-snap-align: center; }
  .role-card img { height: 230px; }
  .selected-role-stage { order: 2; min-height: 430px; width: 100%; }
  .selected-role-stage img { min-height: 430px; }
  .persona-form-card { order: 3; margin-top: 0; padding: 20px; }
  .personality-choices { grid-template-columns: 1fr; }
  .two-fields { grid-template-columns: 1fr; gap: 0; }
  .chat-view {
    position: fixed;
    top: var(--app-top);
    right: 0;
    bottom: auto;
    left: 0;
    width: 100%;
    max-width: 100vw;
    height: var(--app-height);
    min-height: 0;
    overscroll-behavior: none;
  }
  .chat-shell {
    height: 100%;
    min-height: 0;
    display: grid;
    grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  }
  .companion-stage { display: none; }
  .conversation-panel {
    --thread-gutter: 14px;
    position: static;
    height: 100%;
    min-height: 0;
    padding-top: 0;
    background:
      radial-gradient(circle at 82% -8%, rgba(167, 107, 127, .12), transparent 30%),
      var(--paper);
  }
  .conversation-header {
    min-height: calc(64px + var(--safe-top));
    grid-template-columns: 44px 38px minmax(0, 1fr) 28px;
    gap: 9px;
    margin: 0;
    padding: var(--safe-top) 14px 0;
    border: 0;
    border-bottom: 1px solid var(--line-light);
    border-radius: 0;
    color: var(--ink);
    background: rgba(247,241,233,.94);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  .conversation-header .icon-button {
    grid-column: 1;
    display: grid;
    min-width: 44px;
    min-height: 44px;
    color: var(--ink);
    border-color: var(--line-light);
    background: rgba(255,255,255,.48);
  }
  .mobile-chat-avatar {
    grid-column: 2;
    width: 38px;
    height: 38px;
    display: block;
    border: 1px solid var(--line-light);
    border-radius: 13px;
    object-fit: cover;
    object-position: 50% 18%;
    background: #dfd4d9;
  }
  .conversation-heading { grid-column: 3; }
  .online-status {
    grid-column: 4;
    min-width: 28px;
    min-height: 28px;
    border: 0;
    padding: 0;
    background: transparent;
  }
  .online-status span { display: none; }
  .online-status i { margin: auto; }
  .conversation-header strong { font-size: 17px; }
  .conversation-header small { margin-top: 1px; color: var(--muted-dark); font-size: 10px; }
  .chat-scroll {
    min-height: 0;
    padding: 14px 14px 18px;
    background: transparent;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: auto;
  }
  .ai-disclosure {
    max-width: 100%;
    margin-bottom: 16px;
    border-radius: 12px;
    padding: 5px 9px;
    font-size: 9px;
  }
  .message { gap: 8px; margin: 8px 0; }
  .mini-avatar { width: 32px; height: 32px; border-radius: 11px; }
  .message-body { max-width: 82%; }
  .bubble {
    border-radius: 6px 17px 17px;
    padding: 9px 12px;
    font-size: 15px;
    line-height: 1.55;
  }
  .user .bubble { border-radius: 17px 6px 17px 17px; }
  .composer {
    gap: 8px;
    padding: 8px 10px calc(8px + var(--safe-bottom));
    background: rgba(247,241,233,.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  .composer textarea {
    min-height: 48px;
    max-height: 116px;
    padding: 12px 14px;
    border-radius: 16px;
    font-size: 16px;
    line-height: 1.4;
  }
  .composer-hint { display: none; }
  .send-button {
    min-width: 48px;
    width: 48px;
    min-height: 48px;
    border-radius: 16px;
  }
  .send-button span:first-child { display: none; }
  .send-button span:last-child { font-size: 19px; }
}

@media (max-width: 380px) {
  .brand-lockup strong { font-size: 15px; }
  .account-orb { width: 34px; height: 34px; }
  .home-hero h1 { font-size: 26px; }
  .persona-card, .persona-card > img { min-height: 270px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
