:root {
  --bg: #0a0a0f;
  --surface: #12121a;
  --surface2: #1a1a26;
  --border: rgba(255,255,255,.08);
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124,58,237,.15);
  --text: #f4f4f5;
  --muted: #71717a;
  --chip: #27272f;
  --chip-active: #7c3aed;
  --sidebar-w: 320px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#root { min-height: 100vh; }

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.screen-inner { width: 100%; max-width: 520px; }
.screen-wide { max-width: 680px; }

.logo {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 8px;
}

.tagline {
  text-align: center;
  color: var(--muted);
  margin-bottom: 32px;
  font-size: 14px;
}

.step-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  font-size: 18px;
  font-weight: 600;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.back-btn:hover { background: var(--surface2); }

label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  color: #d4d4d8;
}

.field { margin-bottom: 20px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 15px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 140px; resize: vertical; line-height: 1.5; }

.input-row { display: flex; gap: 8px; }
.input-row input { flex: 1; }

.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--accent);
  width: 48px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 18px;
}

.btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.error {
  background: rgba(239,68,68,.12);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
}

.checkbox-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}
.checkbox-row input { margin-top: 3px; accent-color: var(--accent); }

.pill-row { display: flex; gap: 10px; flex-wrap: wrap; }
.pill {
  flex: 1;
  min-width: 90px;
  padding: 12px;
  text-align: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
}
.pill.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: white;
}

.rel-tabs {
  display: flex;
  background: var(--surface2);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.rel-tab {
  flex: 1;
  padding: 10px 6px;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.rel-tab.active { background: var(--accent); color: white; }

.trait-hint { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.trait-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.trait-chip {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--chip);
  border: 1px solid var(--border);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}
.trait-chip.selected { background: var(--chip-active); border-color: var(--chip-active); }

.custom-trait-row { display: flex; gap: 8px; }
.add-trait-btn {
  background: #14b8a6;
  border: none;
  color: white;
  width: 44px;
  border-radius: 12px;
  font-size: 22px;
  cursor: pointer;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

.char-count { text-align: right; font-size: 12px; color: var(--muted); margin-top: 6px; }

.look-title { text-align: center; font-size: 22px; font-weight: 700; margin-bottom: 24px; }

.body-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 20px;
}
@media (max-width: 520px) { .body-grid { grid-template-columns: repeat(2, 1fr); } }

.body-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 16px 8px 12px;
  cursor: pointer;
  text-align: center;
}
.body-card.active { border-color: var(--accent); background: var(--accent-soft); }
.body-card svg { width: 56px; height: 100px; margin: 0 auto 8px; display: block; }
.body-card span { font-size: 12px; color: var(--muted); }

.creating-screen { text-align: center; padding: 60px 24px; }
.creating-screen h2 { font-size: 24px; margin-bottom: 32px; }
.spinner-ring {
  width: 64px; height: 64px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 24px;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chat-app { display: flex; height: 100%; width: 100%; flex: 1; min-height: 0; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
@media (max-width: 768px) { .sidebar { display: none; } }

.sidebar-top { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.sidebar-logo { font-size: 20px; font-weight: 700; color: var(--accent); }

.companion-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.companion-name { font-size: 18px; font-weight: 600; }

.profile-link-btn {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.profile-link-btn:hover { background: var(--accent); color: white; }

.companion-photo {
  flex: 1;
  margin: 0 16px 16px;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface2);
  min-height: 280px;
  display: flex;
  flex-direction: column;
}
.companion-photo .photo-wrap {
  flex: 1;
  min-height: 200px;
  overflow: hidden;
  position: relative;
}
.photo-frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 200px;
  cursor: zoom-in;
}
.photo-frame-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 15%;
  display: block;
}
.portrait-zoom-btn {
  position: absolute;
  bottom: 10px;
  right: 10px;
  z-index: 2;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 12, 20, 0.72);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s, background 0.15s;
}
.portrait-zoom-btn:hover {
  background: rgba(124, 58, 237, 0.9);
  transform: scale(1.06);
}
.photo-frame-mobile {
  min-height: 56px;
}
.photo-frame-mobile .photo-frame-img {
  object-position: center 20%;
}
.photo-frame-mobile .portrait-zoom-btn {
  width: 28px;
  height: 28px;
  bottom: 4px;
  right: 4px;
}
.photo-frame-mobile .portrait-zoom-btn svg {
  width: 14px;
  height: 14px;
}

.portrait-lightbox {
  position: fixed;
  inset: 0;
  z-index: 3500;
  background: rgba(8, 6, 12, 0.94);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 20px 20px;
  cursor: zoom-out;
}
.portrait-lightbox img {
  max-width: min(100%, 720px);
  max-height: calc(100vh - 80px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
  cursor: default;
}
.portrait-lightbox-close {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 3501;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.portrait-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

.sidebar-nav {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 8px;
  margin-top: auto;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}
.nav-item.active { color: var(--accent); }

.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.rate-banner {
  background: rgba(234, 179, 8, .15);
  color: #fde047;
  padding: 10px 16px;
  font-size: 13px;
  text-align: center;
  border-bottom: 1px solid rgba(234, 179, 8, .25);
}

.promo-bar {
  background: linear-gradient(90deg, #4c1d95, #6d28d9);
  padding: 10px 20px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.promo-bar button {
  background: rgba(255,255,255,.15);
  border: none;
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
}

.chat-header-mobile {
  display: none;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
@media (max-width: 768px) { .chat-header-mobile { display: flex; } }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.date-divider {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface2);
  padding: 6px 16px;
  border-radius: 20px;
  align-self: center;
}

.msg-row { display: flex; flex-direction: column; max-width: 75%; }
.msg-row.ai { align-self: flex-start; }
.msg-row.user { align-self: flex-end; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
}
.msg-row.ai .msg-bubble { background: var(--surface2); border-bottom-left-radius: 4px; }
.msg-row.user .msg-bubble { background: var(--accent); border-bottom-right-radius: 4px; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}

.typing { display: flex; gap: 4px; padding: 4px; }
.typing span {
  width: 7px; height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: blink 1.2s infinite both;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,80%,100%{opacity:.3} 40%{opacity:1} }

.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.circle-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

.composer input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 18px;
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.send-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 22px;
  cursor: pointer;
}

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1px solid var(--muted);
  font-size: 10px;
  color: var(--muted);
  margin-left: 4px;
}

.auth-switch {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--muted);
}
.auth-switch button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
}

/* Main app shell (profile settings layout) */
.main-app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.app-sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}

.upgrade-card {
  margin: 16px;
  padding: 16px;
  background: linear-gradient(145deg, #4c1d95, #6d28d9);
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.45;
}
.upgrade-card h3 { font-size: 16px; margin-bottom: 8px; }
.upgrade-card ul { margin: 8px 0 12px 16px; }
.upgrade-card .btn-subscribe {
  width: 100%;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,.2);
  color: white;
  font-weight: 600;
  cursor: pointer;
}

.app-menu { padding: 8px 12px; flex: 1; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: none;
  background: none;
  color: var(--text);
  font-size: 14px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}
.menu-item:hover { background: var(--surface2); }
.menu-item.active { background: var(--accent-soft); color: var(--accent); }
.menu-item.logout { color: #f87171; margin-top: 8px; }
.menu-item.disabled { color: var(--muted); cursor: default; opacity: .6; }

.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.settings-panel {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px 24px;
  max-width: 640px;
}

.settings-panel h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 28px;
}

.settings-form .field { margin-bottom: 24px; }

.settings-form select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 15px;
  outline: none;
}

.birthdate-display {
  padding: 14px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 15px;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.radio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  cursor: pointer;
}
.radio-row input { accent-color: var(--accent); }

.btn-update {
  margin-top: 8px;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-update:hover { background: #2a2a38; }

.main-app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.main-app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
  position: relative;
  padding-bottom: 72px;
}

.bottom-nav {
  display: flex;
  flex-shrink: 0;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  box-shadow: 0 -4px 20px rgba(0,0,0,.4);
}

.bottom-nav .nav-item {
  flex: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav .nav-item:active { opacity: 0.7; }

@media (max-width: 900px) {
  .app-sidebar { display: none; }
  .settings-panel { padding: 20px; }
}

html.dark-forced { color-scheme: dark; }
html.light-forced { color-scheme: light; }
html.light-forced body {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface2: #f4f4f5;
  --text: #18181b;
  --muted: #71717a;
  --border: rgba(0,0,0,.08);
  --chip: #e4e4e7;
}

.look-screen-scroll { max-height: 100vh; overflow-y: auto; padding-bottom: 40px; }
.appearance-section-title {
  margin: 24px 0 12px;
  font-size: 1.05rem;
  color: var(--text);
}
.appearance-picker select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1rem;
}
.appearance-picker.compact .field { margin-bottom: 12px; }
.pill-row-wrap { gap: 8px; }
.pill-row-wrap .pill { font-size: 0.82rem; padding: 8px 12px; }

.chat-mobile-portrait {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.chat-mobile-photo {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  overflow: hidden;
  flex-shrink: 0;
  background: var(--surface2);
}
.chat-mobile-photo .photo-frame { min-height: 56px; width: 100%; height: 100%; }
.chat-mobile-actions { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.chat-mobile-actions strong { font-size: 16px; }
.chat-header-mobile-btns { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.portrait-regen-btn-inline {
  padding: 8px 12px !important;
  font-size: 0.8rem !important;
  width: auto !important;
  margin: 0 !important;
}
.portrait-regen-btn-mobile { margin-top: 0 !important; }

@media (max-width: 768px) {
  .chat-mobile-portrait { display: flex; }
  .chat-header-mobile { display: none; }
}

.portrait-regen-btn {
  width: 100%;
  flex-shrink: 0;
  margin: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.portrait-regen-btn:hover { border-color: #a78bfa; }
.portrait-quota-badge {
  font-size: 0.75rem;
  background: var(--chip);
  padding: 2px 8px;
  border-radius: 999px;
}

.portrait-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.portrait-modal {
  background: var(--surface);
  border-radius: 20px;
  max-width: 520px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  position: relative;
  border: 1px solid var(--border);
}
.portrait-modal h2 { margin-bottom: 8px; font-size: 1.25rem; }
.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--muted);
  cursor: pointer;
}
.btn-upgrade {
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  color: white;
  font-weight: 600;
  cursor: pointer;
}
