:root{
  /* Backgrounds */
  --color-bg-primary: #0a0a0a;
  --color-bg-secondary: #111111;
  --color-bg-tertiary: #1a1a1a;
  --color-bg-elevated: #222222;

  /* Text */
  --color-text-primary: #f5f5f5;
  --color-text-secondary: #e0e0e0;
  --color-text-muted: #999999;

  /* Borders */
  --color-border-subtle: rgba(255, 255, 255, 0.06);
  --color-border-default: rgba(255, 255, 255, 0.10);
  --color-border-strong: rgba(255, 255, 255, 0.16);
  --color-border-focus: rgba(255, 255, 255, 0.40);

  /* Interactive */
  --color-interactive-default: #ffffff;
  --color-interactive-hover: #e8e8e8;
  --color-interactive-pressed: #d0d0d0;

  /* Message Bubbles */
  --color-user-bubble-bg: #2a2a2a;
  --color-assistant-bubble-bg: #161616;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  --shadow-glow-focus: 0 0 0 3px rgba(255, 255, 255, 0.25);

  /* Spacing (8px grid) */
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 9999px;

  /* Legacy mappings for compatibility */
  --bg: var(--color-bg-primary);
  --row: var(--color-assistant-bubble-bg);
  --text: var(--color-text-primary);
  --muted: var(--color-text-muted);
  --input-bg: var(--color-bg-secondary);
  --input-border: var(--color-border-default);
  --accent: var(--color-text-primary);
  --btn-bg: var(--color-interactive-default);
  --btn-fg: var(--color-bg-primary);
}
body.light{
  /* Backgrounds */
  --color-bg-primary: #f7f7f8;
  --color-bg-secondary: #ffffff;
  --color-bg-tertiary: #f0f0f0;
  --color-bg-elevated: #ffffff;

  /* Text */
  --color-text-primary: #0c0c0d;
  --color-text-secondary: #1a1a1a;
  --color-text-muted: #6b7280;

  /* Borders */
  --color-border-subtle: rgba(0, 0, 0, 0.06);
  --color-border-default: rgba(0, 0, 0, 0.10);
  --color-border-strong: rgba(0, 0, 0, 0.16);
  --color-border-focus: rgba(0, 0, 0, 0.40);

  /* Interactive */
  --color-interactive-default: #111111;
  --color-interactive-hover: #2a2a2a;
  --color-interactive-pressed: #3a3a3a;

  /* Message Bubbles */
  --color-user-bubble-bg: #e8e8e8;
  --color-assistant-bubble-bg: #f5f5f5;

  /* Legacy mappings */
  --bg: var(--color-bg-primary);
  --row: var(--color-assistant-bubble-bg);
  --text: var(--color-text-primary);
  --muted: var(--color-text-muted);
  --input-bg: var(--color-bg-secondary);
  --input-border: var(--color-border-default);
  --accent: var(--color-text-primary);
  --btn-bg: var(--color-interactive-default);
  --btn-fg: var(--color-bg-primary);
}

*{ box-sizing:border-box; }
html,body{ height:100%; }

/* Touch optimization */
button, .theme-btn, textarea, a {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
body{
  margin:0;
  color:var(--text);
  background:var(--bg);
  font-family: ui-sans-serif, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.page{ display:flex; flex-direction:column; min-height:100vh; }
.main{ flex:1; display:grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap:16px; padding:16px; align-items:stretch; }
.avatar-pane{ width:100%; background:transparent; padding-right:16px; }
.unity-wrap{ position:sticky; top:64px; max-width:520px; margin:0 auto; }
.avatar-frame{ position:relative; width:100%; max-width:520px; aspect-ratio: 4 / 5; margin:0 auto; overflow:hidden; border-radius:12px; background:#0d0d0d; border:1px solid rgba(255,255,255,0.08); box-shadow:0 10px 30px rgba(0,0,0,.35); }
body.light .avatar-frame{ background:#ffffff; border-color:#e5e7eb; }
.unity-canvas{ width:100%; aspect-ratio: 3 / 4; background:#0d0d0d; border:1px solid rgba(255,255,255,0.08); border-radius:12px; display:block; }
body.light .unity-canvas{ background:#ffffff; border-color:#e5e7eb; }
.avatar-photo{ width:100%; max-width:520px; aspect-ratio: 4 / 5; object-fit: cover; background:#0d0d0d; border:1px solid rgba(255,255,255,0.08); border-radius:12px; display:block; box-shadow:0 10px 30px rgba(0,0,0,.35); margin:0 auto; }
/* Dual video crossfade setup */
.avatar-video{ position:absolute; top:0; left:0; width:100%; height:100%; object-fit:cover; border-radius:12px; opacity:0; transition:opacity 0.5s ease-in-out; z-index:0; }
.avatar-video.active{ opacity:1; z-index:1; }
body.light .avatar-photo{ background:#ffffff; border-color:#e5e7eb; }
/* Fallback image overlays the video and is toggled by JS */
.avatar-fallback{ position:absolute; top:0; left:0; width:100%; height:100%; object-fit:cover; border-radius:12px; z-index:2; }

/* Emotion card under avatar - monochrome */
.emotion-card{
  margin-top: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-subtle);
  background: var(--color-bg-secondary);
  box-shadow: var(--shadow-md);
}
body.light .emotion-card{
  border: 1px solid var(--color-border-subtle);
  background: var(--color-bg-secondary);
  box-shadow: var(--shadow-sm);
}

.em-head{
  display:flex;
  align-items:center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}
.em-emoji{ font-size:18px; }
.em-name{ font-weight:700; text-transform:capitalize; color: var(--color-text-primary); }
.em-strength{ margin-left:auto; color: var(--color-text-muted); font-weight:600; }
body.light .em-strength{ color: var(--color-text-muted); }

/* Monochrome meter */
.em-meter{
  position:relative;
  width:100%;
  height:8px;
  background: var(--color-bg-tertiary);
  border-radius: var(--radius-full);
  overflow:hidden;
  border: 1px solid var(--color-border-subtle);
}
body.light .em-meter{
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-subtle);
}

/* White-to-grey gradient fill - no color */
.em-fill{
  position:absolute;
  left:0;
  top:0;
  bottom:0;
  width:0%;
  background: linear-gradient(90deg, rgba(255,255,255,0.9), rgba(255,255,255,0.4));
  box-shadow: none;
  transition: width .35s ease;
}
body.light .em-fill{
  background: linear-gradient(90deg, rgba(0,0,0,0.7), rgba(0,0,0,0.3));
}

/* Monochrome chips */
.em-tags{
  margin-top: var(--space-3);
  display:flex;
  gap: var(--space-2);
  flex-wrap:wrap;
}
.chip{
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size:12px;
  border: 1px solid var(--color-border-default);
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
}
body.light .chip{
  border: 1px solid var(--color-border-default);
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
}
.hair-sway, .hair-gloss, .blink-area, .blink-lid, .neon, .neon-a, .neon-b{ display:none; }
.avatar-speech{ position:absolute; right:-16px; top:52%; transform: translateX(100%) translateY(-50%); z-index:5; max-width: 520px; pointer-events:none; }
.avatar-speech .bubble{ position:relative; background:var(--row); color:var(--text); border:1px solid var(--input-border); padding:14px 16px; border-radius:14px; font-size:16px; line-height:1.45; box-shadow: var(--shadow); }
.avatar-speech .bubble::before{ content:""; position:absolute; left:-10px; top:50%; transform: translateY(-50%); border-width:8px; border-style:solid; border-color: transparent var(--input-border) transparent transparent; }
.avatar-speech .bubble::after{ content:""; position:absolute; left:-8px; top:50%; transform: translateY(-50%); border-width:8px; border-style:solid; border-color: transparent var(--row) transparent transparent; }
.chat-pane{ display:flex; flex-direction:column; min-width:0; }
/* Topbar */
.topbar{
  position:sticky;
  top:0;
  z-index:10;
  display:flex;
  gap: var(--space-2);
  align-items:center;
  justify-content:center;
  height:56px;
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--color-border-subtle);
  background: linear-gradient(180deg, rgba(10,10,10,0.85), rgba(10,10,10,0.6));
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.topbar-left{
  position:absolute;
  left: var(--space-4);
  display:flex;
  align-items:center;
}
.topbar-actions{
  position:absolute;
  right: var(--space-4);
  display:flex;
  gap: var(--space-2);
  align-items:center;
}

body.light .topbar{
  border-bottom: 1px solid var(--color-border-subtle);
  background: linear-gradient(180deg, rgba(247,247,248,0.9), rgba(247,247,248,0.7));
}

.brand{
  font-weight:600;
  font-size:14px;
  letter-spacing:.2px;
  color: var(--color-text-primary);
  opacity:.9;
}
body.light .brand{ color: var(--color-text-primary); }

.model-chip{
  font-size:12px;
  color: var(--color-text-muted);
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-subtle);
  padding: 4px 10px;
  border-radius: var(--radius-full);
}
body.light .model-chip{
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-subtle);
}

/* Theme button with proper hover/focus states */
.theme-btn{
  background: transparent;
  border: 1px solid var(--color-border-default);
  color: var(--color-text-primary);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  cursor:pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.theme-btn:hover{
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-strong);
}
.theme-btn:active{
  background: var(--color-bg-elevated);
}
body.light .theme-btn{
  border-color: var(--color-border-default);
}
body.light .theme-btn:hover{
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-strong);
}

.theme-btn.icon-only{
  width:36px;
  height:36px;
  padding:0;
  display:grid;
  place-items:center;
  font-size:18px;
}
.theme-btn .icon{ width:18px; height:18px; display:block; }
.theme-btn.icon-only .icon{ width:20px; height:20px; }

/* Ready Player Me modal */
.rpm-modal{ position:fixed; inset:0; display:flex; align-items:center; justify-content:center; background:rgba(0,0,0,.55); z-index:1000 }
.rpm-modal[hidden]{ display:none }
.rpm-panel{ width:min(1000px, 95vw); height:min(720px, 92vh); background:var(--bg); border:1px solid rgba(255,255,255,0.1); border-radius:14px; overflow:hidden; box-shadow:0 14px 50px rgba(0,0,0,.5); position:relative }
.rpm-panel iframe{ width:100%; height:100%; border:0; display:block; background:#0e1622 }
.rpm-close{ position:absolute; top:8px; right:10px; z-index:2; background:#1b1f26; color:var(--text); border:1px solid rgba(255,255,255,0.1); border-radius:10px; padding:6px 10px; cursor:pointer }
body.light .rpm-panel{ background:#fff; border-color:#e5e7eb }
body.light .rpm-close{ background:#fff; color:#111; border-color:#e5e7eb }

.chat-scroll{ flex:1; overflow:auto; display:flex; justify-content:flex-end; scroll-behavior:smooth; overscroll-behavior:contain; }
.chat{ width:100%; max-width:900px; padding: 12px 16px 140px; margin:0 auto; }

/* Message container */
.message{
  display:grid;
  grid-template-columns: 40px 1fr;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-radius: var(--radius-lg);
  line-height:1.65;
  max-width: 85%;
}
.message + .message{ margin-top: var(--space-5); }

/* User message - right-aligned feel with darker bubble */
.message.user{
  background: var(--color-user-bubble-bg);
  border: 1px solid var(--color-border-subtle);
  margin-left: 15%;
  border-radius: var(--radius-lg) var(--radius-sm) var(--radius-lg) var(--radius-lg);
}
body.light .message.user{
  background: var(--color-user-bubble-bg);
  border-color: var(--color-border-subtle);
}

/* Assistant message - left-aligned with subtle bg */
.message.assistant{
  background: var(--color-assistant-bubble-bg);
  border: 1px solid var(--color-border-subtle);
  margin-right: 15%;
  border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
}
body.light .message.assistant{
  background: var(--color-assistant-bubble-bg);
  border-color: var(--color-border-subtle);
}

/* Avatar styling - smaller and cleaner */
.avatar{
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:600;
  font-size: 12px;
  background: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
  flex-shrink: 0;
}
.avatar.user{ background: var(--color-bg-elevated); }
.avatar.ai{ background:transparent; padding:0; overflow:hidden; }

/* Message content */
.content{
  white-space:pre-wrap;
  word-wrap:break-word;
  color: var(--color-text-secondary);
}

/* Composer area with gradient fade */
.composer-wrap{
  position:sticky;
  bottom:0;
  display:flex;
  justify-content:center;
  padding: var(--space-4) var(--space-4) var(--space-6);
  padding-bottom: env(safe-area-inset-bottom, var(--space-6));
  background: linear-gradient(to top, var(--color-bg-primary) 70%, transparent);
}
body.light .composer-wrap{
  background: linear-gradient(to top, var(--color-bg-primary) 70%, transparent);
}

.composer{ width:min(760px, 100%); }

.controls{
  display:flex;
  align-items:center;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
  color: var(--color-text-muted);
  font-size:12px;
}
.switch{ display:flex; align-items:center; gap: var(--space-2); }
.switch input{ width:18px; height:18px; accent-color: var(--color-text-primary); }
.tip{ margin-left:auto; }

/* Unified input container */
.inputbar{
  display:flex;
  gap: 0;
  align-items:flex-end;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-2);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.inputbar:focus-within{
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-glow-focus);
}

textarea{
  flex:1;
  min-height:24px;
  max-height:220px;
  height:44px;
  resize:none;
  outline:none;
  background: transparent;
  color: var(--color-text-primary);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-3);
  line-height:1.5;
  caret-color: var(--color-text-primary);
  overflow-y:auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
textarea::-webkit-scrollbar{ display: none; }
textarea::placeholder{ color: var(--color-text-muted); }

/* Send button with proper states */
button.send{
  background: var(--color-interactive-default);
  color: var(--color-bg-primary);
  border: none;
  border-radius: var(--radius-md);
  font-weight:600;
  padding: var(--space-3) var(--space-4);
  cursor:pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}
button.send:hover{
  background: var(--color-interactive-hover);
  transform: translateY(-1px);
}
button.send:active{
  background: var(--color-interactive-pressed);
  transform: translateY(0);
}
button.send:disabled{
  opacity:.5;
  cursor:not-allowed;
  transform: none;
}

.hint{
  margin-top: var(--space-2);
  text-align:center;
  color: var(--color-text-muted);
  font-size:12px;
}

/* 1024px - Tablet (iPad landscape) */
@media (max-width: 1024px) {
  .main { gap: 12px; }
  .unity-wrap { max-width: 480px; }
}

/* 768px - Phablet/iPad portrait */
@media (max-width: 768px) {
  .main { grid-template-columns: 1fr; padding: 16px 10px; }
  .avatar-pane { padding-right: 0; }
  .unity-wrap { position: relative; top: auto; max-width: 380px; margin: 0 auto 12px; }
  .avatar-frame, .avatar-photo { max-width: 380px; }
}

@media (max-width: 980px){
  .topbar{ padding:0 16px; }
  .topbar-left{ position:static; left:auto; }
  .topbar-actions{ position:static; right:auto; flex:1; justify-content:flex-end; }
  .main{ grid-template-columns: 1fr; padding:16px 12px; }
  .avatar-pane{ padding-right:0; border-right:none; }
  .unity-wrap{ position:relative; top:auto; margin:0 auto 16px; max-width:420px; }
  .avatar-frame, .avatar-photo{ max-width:420px; aspect-ratio: 3 / 4; }
  .chat-scroll{ justify-content:center; }
  .composer-wrap{ position:sticky; bottom:0; padding:16px 12px 24px; }
  .chat{ padding: 16px 12px 140px; }
  .avatar-speech{ display:none; }
}

/* Animations removed */

@media (max-width: 640px){
  .topbar{ padding:0 14px; height:auto; }
  .topbar-actions{ gap:6px; }
  #loginBtn{ padding:6px 10px; font-size:13px; }
  .chat{ padding: 16px 10px 120px; }
  .message{ grid-template-columns:48px 1fr; gap:16px; padding:20px; border-radius:14px; }
  .avatar{ width:44px; height:44px; font-size:13px; }
  textarea{ min-height:32px; height:40px; padding:10px 12px; }
}

.avatar.ai img{ width:100%; height:100%; border-radius:50%; object-fit:cover; display:block; }

.clerk-signin { display:flex; justify-content:center; align-items:center; min-height:520px; }

.user-button { display:inline-flex; align-items:center; }
.user-button[hidden] { display:none !important; }

.error { color:#ef4444; text-align:center; }


@media (max-width: 480px){
  .topbar{ padding:0 12px; }
  .topbar-actions{ justify-content:flex-end; gap:6px; }
  #loginBtn{ flex:1 1 auto; min-width:0; padding:6px 8px; font-size:12px; }
  #voiceMode.theme-btn.icon-only, #theme.theme-btn.icon-only{ width:32px; height:32px; font-size:16px; }
  .composer-wrap{ padding:12px 10px 20px; }
  .composer{ width:100%; }
}

/* 360px - Compact phones (iPhone SE, Galaxy S) */
@media (max-width: 360px) {
  .message { max-width: 92%; }
  .message.user { margin-left: 8%; }
  .message.assistant { margin-right: 8%; }
  .message { padding: var(--space-3) var(--space-4); }
  .chat { padding: 12px 8px 100px; }
  .composer-wrap { padding: 10px 8px 16px; }
  textarea { height: 36px; font-size: 14px; }
}


/* ==================== */
/* ONBOARDING & CHARACTER SELECTION */
/* ==================== */

.onboarding-panel {
  width: min(680px, 95vw);
  max-height: 90vh;
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  overflow-y: auto;
  position: relative;
}

.onboarding-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin: 0 0 var(--space-2) 0;
  color: var(--color-text-primary);
  text-align: center;
}

.onboarding-subtitle {
  font-size: 1rem;
  color: var(--color-text-muted);
  margin: 0 0 var(--space-6) 0;
  text-align: center;
}

/* Character Grid */
.character-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.character-grid[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .character-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 400px) {
  .character-grid {
    grid-template-columns: 1fr;
  }
}

/* Character Card */
.character-card {
  background: var(--color-bg-tertiary);
  border: 2px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.character-card:hover {
  border-color: var(--color-border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.character-card.selected {
  border-color: var(--color-interactive-default);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
}

body.light .character-card.selected {
  border-color: var(--color-interactive-default);
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.15);
}

.card-avatar {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-bottom: var(--space-3);
  background: var(--color-bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.create-card .card-avatar {
  font-size: 2rem;
  color: var(--color-text-muted);
  border: 2px dashed var(--color-border-default);
  background: transparent;
}

.card-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.card-persona {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  line-height: 1.4;
}

/* Custom Character Card Actions */
.character-card.custom-character {
  position: relative;
}

.card-actions {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.character-card.custom-character:hover .card-actions {
  opacity: 1;
}

.card-action-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-sm);
  background: var(--color-bg-secondary);
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.card-action-btn svg {
  width: 14px;
  height: 14px;
}

.card-action-btn:hover {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border-color: var(--color-border-strong);
}

.card-action-btn.delete-btn:hover {
  background: #ef444420;
  color: #ef4444;
  border-color: #ef4444;
}

body.light .card-action-btn {
  background: var(--color-bg-secondary);
  border-color: var(--color-border-default);
}

body.light .card-action-btn:hover {
  background: var(--color-bg-tertiary);
}

/* Custom Character Form */
.custom-form {
  padding: var(--space-4) 0;
}

.custom-form h3 {
  font-size: 1.25rem;
  margin: var(--space-4) 0;
  color: var(--color-text-primary);
}

.back-btn {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: var(--space-2);
  font-size: 0.9rem;
}

.back-btn:hover {
  color: var(--color-text-primary);
}

.form-group {
  margin-bottom: var(--space-5);
}

.form-group label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.form-group input[type="text"],
.form-group textarea {
  width: 100%;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  color: var(--color-text-primary);
  font-family: inherit;
  font-size: 1rem;
}

.form-group input[type="text"]:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-border-focus);
  box-shadow: var(--shadow-glow-focus);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

.char-count {
  display: block;
  text-align: right;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

/* Image Upload Zone */
.image-drop-zone {
  width: 100%;
  min-height: 150px;
  border: 2px dashed var(--color-border-default);
  border-radius: var(--radius-lg);
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.image-drop-zone:hover,
.image-drop-zone.dragover {
  border-color: var(--color-border-strong);
  background: var(--color-bg-tertiary);
}

.image-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-muted);
  padding: var(--space-4);
  text-align: center;
}

.image-placeholder .hint {
  font-size: 0.75rem;
  opacity: 0.7;
}

.image-preview {
  position: relative;
  width: 120px;
  height: 120px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius-md);
}

.remove-image {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border-default);
  color: var(--color-text-primary);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.remove-image:hover {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
}

/* Footer Buttons */
.onboarding-footer {
  display: flex;
  gap: var(--space-4);
  justify-content: center;
  flex-wrap: wrap;
}

.primary-btn {
  background: var(--color-interactive-default);
  color: var(--color-bg-primary);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-6);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

.primary-btn:hover:not(:disabled) {
  background: var(--color-interactive-hover);
  transform: translateY(-1px);
}

.primary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.secondary-btn {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-6);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.secondary-btn:hover {
  background: var(--color-bg-tertiary);
  border-color: var(--color-border-strong);
}

/* Responsive adjustments */
@media (max-width: 640px) {
  .onboarding-panel {
    padding: var(--space-5);
  }

  .onboarding-title {
    font-size: 1.4rem;
  }

  .card-avatar {
    width: 64px;
    height: 64px;
  }

  .onboarding-footer {
    flex-direction: column;
  }

  .primary-btn,
  .secondary-btn {
    width: 100%;
  }
}

/* ========================================
   Chat Sidebar Styles
   ======================================== */

:root {
  --sidebar-width: 260px;
}

/* Sidebar Container */
.chat-sidebar {
  position: fixed;
  top: 0;
  left: calc(-1 * var(--sidebar-width) - 20px);
  width: var(--sidebar-width);
  max-width: 85vw;
  height: 100vh;
  background: var(--color-bg-secondary);
  border-right: 1px solid var(--color-border-default);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: left 0.3s ease;
  box-shadow: var(--shadow-lg);
}

.chat-sidebar.open {
  left: 0;
}

/* Sidebar Overlay */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.new-chat-btn {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.new-chat-btn:hover {
  background: var(--color-bg-elevated);
  border-color: var(--color-border-strong);
}

.sidebar-close {
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  transition: color 0.2s ease, background-color 0.2s ease;
  line-height: 1;
}

.sidebar-close:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-tertiary);
}

/* Sidebar Content */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

/* Profile Section */
.sidebar-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border-subtle);
}

.profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--color-bg-tertiary);
  border: 2px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  font-weight: 600;
  overflow: hidden;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-text-primary);
}

/* Sidebar Section */
.sidebar-section {
  display: flex;
  flex-direction: column;
}

.section-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-2);
}

/* Character List in Sidebar */
.sidebar-character-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-character-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.sidebar-character-item:hover {
  background: var(--color-bg-tertiary);
}

.sidebar-character-item.selected {
  border-color: var(--color-interactive-default);
  background: var(--color-bg-tertiary);
}

.sidebar-character-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.sidebar-character-item.selected .sidebar-character-avatar {
  border-color: var(--color-interactive-default);
}

.sidebar-character-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.sidebar-character-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-character-persona {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Add Companion Button */
.add-companion-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-top: var(--space-2);
  border-radius: var(--radius-md);
  border: 1px dashed var(--color-border-default);
  background: transparent;
  color: var(--color-text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease;
}

.add-companion-btn:hover {
  border-color: var(--color-interactive-default);
  color: var(--color-text-primary);
  background: var(--color-bg-tertiary);
}

.add-companion-btn .add-icon {
  font-size: 1rem;
  font-weight: 600;
}

/* Thread List */
.threads-section {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.thread-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  overflow-y: auto;
  flex: 1;
}

.thread-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color 0.2s ease;
  min-height: 44px;
}

.thread-item:hover {
  background: var(--color-bg-tertiary);
}

.thread-item.active {
  background: var(--color-bg-elevated);
}

.thread-title {
  flex: 1;
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: var(--space-2);
}

.thread-item.active .thread-title {
  color: var(--color-text-primary);
}

.thread-delete {
  opacity: 0;
  background: transparent;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: opacity 0.2s ease, color 0.2s ease, background-color 0.2s ease;
  flex-shrink: 0;
}

.thread-item:hover .thread-delete {
  opacity: 1;
}

.thread-delete:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-tertiary);
}

/* Mobile Responsive */
@media (max-width: 480px) {
  .chat-sidebar {
    width: 85vw;
  }
}

/* ========================================
   Delete Confirmation Modal
   ======================================== */

.confirm-panel {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.confirm-title {
  margin: 0 0 var(--space-3) 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text-primary);
}

.confirm-message {
  margin: 0 0 var(--space-6) 0;
  font-size: 0.95rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
}

.danger-btn {
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-md);
  border: none;
  background: #ef4444;
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.danger-btn:hover:not(:disabled) {
  background: #dc2626;
  transform: translateY(-1px);
}

.danger-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

