:root {
  --bg: #08080d;
  --bg-elevated: #0e0e16;
  --surface: #13131c;
  --surface-2: #1a1a27;
  --surface-3: #222233;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f0f0f5;
  --text-muted: #8b8ba3;
  --text-dim: #5c5c72;
  --accent: #9d7cff;
  --accent-soft: rgba(157, 124, 255, 0.14);
  --accent-glow: rgba(157, 124, 255, 0.25);
  --user-bubble: linear-gradient(135deg, #5b45e8, #3d3580);
  --assistant-bubble: #1c1c28;
  --ok: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --radius-pill: 999px;
  --shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 12px 32px rgba(0, 0, 0, 0.35);
  --focus-ring: 0 0 0 3px rgba(157, 124, 255, 0.28);
  --ease: 160ms ease;
  --font: "Inter", system-ui, sans-serif;
  --font-display: "Playfair Display", Georgia, serif;
  --left-w: 280px;
  --right-w: 260px;
  --chat-max: 480px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(157, 124, 255, 0.08), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(91, 69, 232, 0.05), transparent),
    var(--bg);
}

#app-root {
  height: 100dvh;
  overflow: hidden;
}

/* --- Screens --- */

.screen {
  display: none;
  height: 100%;
  animation: screenIn 0.35s ease;
}

.screen-active {
  display: flex;
  flex-direction: column;
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- HOME --- */

.home-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 28px 20px;
  overflow-x: hidden;
  overflow-y: auto;
  /* Scroll ok, barra nascosta */
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.home-shell::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.home-footer {
  margin-top: 28px;
  padding-top: 16px;
  flex-shrink: 0;
}

.home-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 36px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  font-size: 1.5rem;
  color: var(--accent);
  filter: drop-shadow(0 0 10px rgba(157, 124, 255, 0.2));
  line-height: 1;
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.home-header .brand-lockup {
  align-items: center;
}

.brand-tagline {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.home-hero {
  margin-bottom: 32px;
}

.home-hero h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 500;
}

.home-hero p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.55;
  max-width: 520px;
}

.home-section {
  margin-bottom: 28px;
}

.section-head {
  margin-bottom: 14px;
}

.section-head h3 {
  margin: 0;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  font-weight: 600;
}

.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.char-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: border-color var(--ease), transform var(--ease), box-shadow var(--ease), background var(--ease);
}

.char-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
  background: var(--surface-2);
}

.char-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-color: rgba(157, 124, 255, 0.45);
}

.char-card-avatar {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  font-weight: 700;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.char-card-name {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
}

.char-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 2px 0 0;
}

.char-card-trait {
  font-size: 0.75rem;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  margin-top: auto;
}

.create-ai-card {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 20px 22px;
  margin-top: 8px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: border-color var(--ease), background var(--ease), transform var(--ease);
}

.create-ai-card:hover {
  border-color: rgba(157, 124, 255, 0.45);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.create-ai-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.create-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--accent);
  flex-shrink: 0;
}

.create-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.create-text strong {
  font-size: 0.95rem;
}

.create-text small {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.home-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

/* --- CHAT LAYOUT --- */

.chat-layout {
  display: grid;
  grid-template-columns: var(--left-w) 1fr var(--right-w);
  height: 100%;
  overflow: hidden;
}

.panel-left,
.panel-right {
  background: var(--bg-elevated);
  border-color: var(--border);
  overflow-y: auto;
}

.panel-left {
  border-right: 1px solid var(--border);
  padding: 28px 22px;
}

.panel-right {
  border-left: 1px solid var(--border);
  padding: 24px 20px;
}

.panel-center {
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  background: var(--bg);
}

/* Sidebar profilo */

.sidebar-profile {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar-avatar {
  width: 88px;
  height: 88px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-sm);
}

.sidebar-profile h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 600;
}

.sidebar-subtitle {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sidebar-backstory {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.55;
  color: #b8b8cc;
}

.sidebar-section h4 {
  margin: 0 0 8px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}

.sidebar-likes {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.sidebar-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

/* Chat phone frame */

.chat-phone {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: var(--chat-max);
  height: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.chat-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.chat-header-info strong {
  display: block;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header-status {
  font-size: 0.75rem;
  color: var(--ok);
}

/* Stato conversazione */

.scene-state-card,
.chat-scene-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}

.scene-state-card {
  padding: 12px 14px;
  background: var(--surface);
}

.chat-scene-banner {
  margin: 0 12px;
  padding: 10px 14px;
  flex-shrink: 0;
  background: var(--surface-2);
}

.scene-state-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.scene-state-icon svg {
  width: 18px;
  height: 18px;
}

.scene-state-body {
  flex: 1;
  min-width: 0;
}

.scene-state-body strong {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
}

.scene-state-kicker {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.scene-state-hint {
  margin: 4px 0 0;
  font-size: 0.76rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.scene-state-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.scene-state-chat {
  border-color: rgba(96, 165, 250, 0.25);
  background: rgba(96, 165, 250, 0.06);
}

.scene-state-chat .scene-state-icon {
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
}

.scene-state-chat .scene-state-pill {
  background: rgba(96, 165, 250, 0.12);
  color: #93c5fd;
}

.scene-state-media {
  border-color: rgba(52, 211, 153, 0.25);
  background: rgba(52, 211, 153, 0.06);
}

.scene-state-media .scene-state-icon {
  background: rgba(52, 211, 153, 0.15);
  color: #6ee7b7;
}

.scene-state-media .scene-state-pill {
  background: rgba(52, 211, 153, 0.12);
  color: #6ee7b7;
}

.scene-state-live {
  border-color: rgba(251, 191, 36, 0.28);
  background: rgba(251, 191, 36, 0.07);
}

.scene-state-live .scene-state-icon {
  background: rgba(251, 191, 36, 0.16);
  color: #fcd34d;
}

.scene-state-live .scene-state-pill {
  background: rgba(251, 191, 36, 0.14);
  color: #fcd34d;
}

.scene-state-intimate {
  border-color: rgba(248, 113, 113, 0.28);
  background: rgba(248, 113, 113, 0.07);
}

.scene-state-intimate .scene-state-icon {
  background: rgba(248, 113, 113, 0.16);
  color: #fca5a5;
}

.scene-state-intimate .scene-state-pill {
  background: rgba(248, 113, 113, 0.14);
  color: #fca5a5;
}

.scene-state-changed {
  animation: scenePulse 0.55s ease;
}

@keyframes scenePulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.015); box-shadow: 0 0 0 3px rgba(157, 124, 255, 0.12); }
  100% { transform: scale(1); }
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-shrink: 0;
}

.chat-composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  color: var(--text);
  padding: 12px 16px;
  font: inherit;
  font-size: 0.92rem;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.4;
}

.chat-composer textarea:focus {
  outline: none;
  border-color: rgba(157, 124, 255, 0.45);
  box-shadow: var(--focus-ring);
}

.chat-composer button {
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6b52e8);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity var(--ease), filter var(--ease), transform var(--ease);
}

.chat-composer button:hover:not(:disabled) {
  filter: brightness(1.06);
}

.chat-composer button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.chat-composer button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Messages */

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
  animation: fadeIn 0.25s ease;
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-row.assistant {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.message-bubble {
  padding: 11px 14px;
  border-radius: 20px;
  line-height: 1.5;
  word-wrap: break-word;
  max-width: 100%;
  font-size: 0.92rem;
}

.message-row.user .message-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 5px;
  color: #f8f8ff;
}

.message-row.assistant .message-bubble {
  background: var(--assistant-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.message-row.system-note {
  align-self: center;
  max-width: 95%;
}

.message-row.system-note .message-bubble {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 0.78rem;
  text-align: center;
  padding: 4px 10px;
}

.message-body { white-space: pre-wrap; }

.action-text {
  font-style: italic;
  color: #c4b5fd;
  opacity: 0.92;
}

.message-row.user .action-text { color: #dbeafe; }

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 13px 16px;
  min-width: 52px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Controls panel */

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.controls-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 500;
}

.control-block h4 {
  margin: 0 0 10px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  font-weight: 600;
}

.usage-card {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  margin-bottom: 8px;
}

.usage-card.usage-total {
  border-color: rgba(157, 124, 255, 0.2);
  background: var(--accent-soft);
}

.usage-label {
  display: block;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.usage-value {
  display: block;
  font-size: 0.95rem;
  font-weight: 600;
}

.usage-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.controls-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Buttons & status */

.icon-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.icon-btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

button {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  color: white;
  background: linear-gradient(135deg, var(--accent), #6b52e8);
  cursor: pointer;
  transition: filter var(--ease), border-color var(--ease), background var(--ease), opacity var(--ease);
}

button:hover:not(:disabled):not(.btn-disabled):not(.icon-btn):not(.char-card):not(.create-ai-card):not(.onboard-choice):not(.scenario-card):not(.scenario-pick-row):not(.memory-row-delete) {
  filter: brightness(1.06);
}

button:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  filter: none;
}

.btn-secondary:hover:not(:disabled):not(.btn-disabled) {
  background: var(--surface-3);
  border-color: var(--border-strong);
  filter: none;
}

.btn-sm,
.btn-small {
  padding: 7px 12px;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
  margin-bottom: 8px;
}

.btn-danger {
  border-color: rgba(248, 113, 113, 0.35) !important;
  color: #fca5a5 !important;
  background: rgba(248, 113, 113, 0.08);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.14);
  filter: none;
}

.btn-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.status-dot {
  width: 7px;
  height: 7px;
  min-width: 7px;
  min-height: 7px;
  max-width: 7px;
  max-height: 7px;
  border-radius: 50%;
  background: var(--warn);
  flex-shrink: 0;
  align-self: center;
}

.status-pill,
.home-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.status-pill.ok .status-dot,
.home-status.ok .status-dot { background: var(--ok); }

.status-pill.error .status-dot,
.home-status.error .status-dot { background: var(--error); }

/* Profile traits */

.profile-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.trait-chip {
  display: inline-flex;
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  border: 1px solid rgba(157, 124, 255, 0.25);
  color: #ddd6fe;
  font-size: 0.78rem;
  font-weight: 500;
}

/* Dialogs */

.settings-dialog,
.creator-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: 520px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop,
.creator-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.settings-dialog form,
.creator-form {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-dialog h2,
.creator-header h2 {
  margin: 0;
  font-family: var(--font-display);
}

.settings-hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.settings-hint a { color: var(--accent); }

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.settings-field input,
.creator-field input,
.creator-field textarea,
.creator-field select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 12px;
  font: inherit;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.settings-field input:focus,
.creator-field input:focus,
.creator-field textarea:focus,
.creator-field select:focus {
  outline: none;
  border-color: rgba(157, 124, 255, 0.45);
  box-shadow: var(--focus-ring);
}

.settings-actions,
.creator-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.creator-steps {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.step-btn {
  min-width: auto;
  padding: 6px 12px;
  font-size: 0.76rem;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.step-btn.active {
  background: linear-gradient(135deg, var(--accent), #6b52e8);
  color: white;
  border-color: transparent;
}

.step-btn.done { color: #c4b5fd; }

.creator-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.creator-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
}

.creator-trait-grid { display: flex; flex-direction: column; gap: 14px; }

.trait-option-hint {
  margin: 4px 0 0;
  font-size: 0.76rem;
  color: var(--text-dim);
}

.preview-card {
  display: flex;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.preview-avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.preview-backstory {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.preview-traits {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mobile-only { display: none; }

/* Responsive */

@media (max-width: 1024px) {
  .chat-layout {
    grid-template-columns: 1fr;
  }

  .panel-left { display: none; }

  .panel-right {
    position: fixed;
    top: 0;
    right: 0;
    width: min(var(--right-w), 85vw);
    height: 100%;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.5);
  }

  .panel-right.open { transform: translateX(0); }

  .mobile-only { display: flex; }

  .panel-center { padding: 0; }

  .chat-phone {
    max-width: 100%;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}

@media (max-width: 640px) {
  .home-shell { padding: 16px; }
  .char-grid { grid-template-columns: 1fr 1fr; }
  .creator-row { grid-template-columns: 1fr; }
}

@media (max-width: 400px) {
  .char-grid { grid-template-columns: 1fr; }
}

/* Access gate VPS */
.access-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at top, rgba(157, 124, 255, 0.1), transparent 55%), var(--bg);
  padding: 24px;
}

.access-gate[hidden] { display: none !important; }

.access-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: var(--shadow);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 10px;
}

.access-card .brand-lockup {
  justify-content: center;
  margin-bottom: 4px;
}

.access-card h1 {
  font-family: "Playfair Display", serif;
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.access-card > p {
  color: var(--text-muted);
  margin: 12px 0 4px;
  font-weight: 500;
}

.access-card .access-sub {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 0.88rem;
  font-weight: 400;
}

.access-error {
  color: #f87171;
  font-size: 0.9rem;
  margin: 8px 0 0;
}

.btn-block {
  width: 100%;
  margin-top: 12px;
}

.admin-panel {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.admin-panel h3,
#settings-api-block h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.admin-create-row {
  display: grid;
  grid-template-columns: 1fr 110px auto;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-create-row input,
.admin-create-row button {
  height: 40px;
}

.admin-create-row input {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.admin-create-row input:focus {
  outline: none;
  border-color: rgba(157, 124, 255, 0.45);
  box-shadow: var(--focus-ring);
}

.admin-keys-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
}

.admin-key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.admin-key-row small {
  display: block;
  color: var(--text-muted);
}

.admin-new-key {
  margin-bottom: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  border: 1px dashed rgba(157, 124, 255, 0.4);
  word-break: break-all;
  font-family: monospace;
  font-size: 0.85rem;
}

.admin-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.btn-small {
  padding: 7px 12px;
  font-size: 0.8rem;
}

.admin-logs {
  margin-top: 12px;
}

.admin-logs-pre {
  max-height: 200px;
  overflow: auto;
  font-size: 0.72rem;
  background: rgba(0, 0, 0, 0.25);
  padding: 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  white-space: pre-wrap;
}

@media (max-width: 640px) {
  .admin-create-row {
    grid-template-columns: 1fr;
  }
}

.home-load-error {
  color: #f87171;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.35);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 0.92rem;
}

#app-root[hidden] {
  display: none !important;
}
/* --- Onboarding --- */
.onboard-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 32px 24px 40px;
}
.onboard-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 36px;
}
.onboard-brand h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.8rem;
  font-weight: 600;
}
.onboard-form h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 600;
}
.onboard-lead {
  margin: 0 0 24px;
  color: var(--text-muted);
  line-height: 1.5;
}
.onboard-choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 28px;
}
.onboard-choices-grid {
  grid-template-columns: 1fr 1fr;
}
.onboard-choice {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease), transform var(--ease), box-shadow var(--ease);
}
.onboard-choice:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.onboard-choice:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.onboard-choice.selected {
  border-color: rgba(157, 124, 255, 0.55);
  background: var(--accent-soft);
}
.onboard-choice strong { display: block; margin-bottom: 4px; }
.onboard-choice small { color: var(--text-muted); font-size: 0.82rem; }
.onboard-nav {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.home-shell-v2 {
  max-width: 1040px;
}
#screen-home.screen-active {
  overflow: hidden;
}
.home-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.home-hero-v2 h2 {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  margin: 0 0 8px;
}
.pref-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}
.pref-chip {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.memory-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.memory-row {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease), transform var(--ease);
}
.memory-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  transform: translateY(-1px);
  filter: none;
}
.memory-row-avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.memory-row-body {
  flex: 1;
  min-width: 0;
}
.memory-row-body strong {
  display: block;
  font-size: 0.95rem;
  margin-bottom: 2px;
}
.memory-row-body p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.memory-row-meta {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: var(--text-dim);
  text-align: right;
}
.memory-row-delete {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  border: 1px solid transparent;
  font-size: 1.1rem;
  line-height: 1;
}
.memory-row-delete:hover {
  color: #fca5a5;
  border-color: rgba(248, 113, 113, 0.35);
  filter: none;
}
.memory-empty {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.char-grid-v2 {
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.char-card-v2 {
  min-height: 168px;
  align-items: flex-start;
}
.char-card-tagline {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.char-card-secondary {
  opacity: 0.92;
}
.section-hint {
  margin: -4px 0 14px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.scenario-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}
.scenario-card {
  text-align: left;
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--scenario-accent, #9d7cff) 18%, transparent), transparent 55%),
    var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  color: var(--text);
  cursor: pointer;
  transition: transform var(--ease), border-color var(--ease), box-shadow var(--ease);
}
.scenario-card:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--scenario-accent, #9d7cff) 45%, var(--border));
  box-shadow: var(--shadow-sm);
}
.scenario-card:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.scenario-card-mood {
  display: inline-block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--scenario-accent, var(--accent));
  margin-bottom: 8px;
}
.scenario-card strong {
  display: block;
  font-family: var(--font-display);
  font-size: 1.15rem;
  margin-bottom: 8px;
}
.scenario-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}
#start-scenario-list {
  max-height: 280px;
  overflow-y: auto;
}
#start-scenario-list:not([hidden]) {
  margin-top: 8px;
}

.scenario-pick-row {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease);
}
.scenario-pick-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-3);
}
.scenario-pick-row:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}
.btn-small {
  padding: 7px 12px;
  font-size: 0.8rem;
}

/* ===== Account utente ===== */
#screen-account.screen-active {
  overflow: hidden;
}
.account-shell {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 48px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.account-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}
.account-header h1 {
  margin: 0;
  font-size: 1.6rem;
}
.account-sub {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}
.account-grid {
  display: grid;
  gap: 16px;
}
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: none;
}
.account-card h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}
.account-subhead {
  margin: 20px 0 10px;
  font-size: 0.95rem;
}
.account-prefs-list {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 12px;
  margin: 16px 0;
}
.account-prefs-list dt {
  color: var(--text-muted);
  font-size: 0.85rem;
}
.account-prefs-list dd {
  margin: 0;
  font-weight: 600;
}
.account-usage-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin: 16px 0 8px;
}
.account-usage-row.is-admin-metrics {
  grid-template-columns: repeat(2, 1fr);
}
.account-metric {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.account-metric-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.account-metric strong {
  font-size: 1.25rem;
}
.account-metric small {
  color: var(--text-muted);
  font-size: 0.78rem;
}
.account-diag-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
#admin-key-budget {
  width: 100px;
  min-width: 100px;
}
@media (max-width: 720px) {
  .account-usage-row {
    grid-template-columns: 1fr;
  }
  .account-prefs-list {
    grid-template-columns: 1fr;
  }
}

#account-admin-card[hidden] {
  display: none !important;
}

.admin-logs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  margin-top: 8px;
}
.admin-turn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.admin-turn header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.85rem;
}
.admin-turn header small {
  color: var(--text-muted);
}
.admin-turn-user,
.admin-turn-ai {
  margin: 0 0 6px;
  font-size: 0.9rem;
  line-height: 1.4;
}
.admin-turn-user {
  color: var(--text-muted);
}
.admin-turn-user::before {
  content: "Utente ? ";
  font-weight: 600;
  color: var(--text-muted);
}
.admin-turn-ai::before {
  content: "AI ? ";
  font-weight: 600;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}
.char-card-avatar,
.sidebar-avatar,
.chat-header-avatar,
.msg-avatar,
.preview-avatar {
  overflow: hidden;
  padding: 0;
}
.char-card-v2 .char-card-avatar {
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
}

.message-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(520px, 100%);
}
.msg-notice {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  line-height: 1.35;
  border: 1px solid transparent;
}
.msg-notice-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.68rem;
  opacity: 0.9;
}
.msg-notice-body {
  color: inherit;
}
.msg-notice-thought {
  background: var(--accent-soft);
  border-color: rgba(157, 124, 255, 0.35);
  color: #c4b5fd;
}
.msg-notice-action {
  background: rgba(52, 211, 153, 0.12);
  border-color: rgba(52, 211, 153, 0.35);
  color: #6ee7b7;
}
.msg-notice-user-action {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.35);
  color: #7dd3fc;
  align-self: flex-end;
}
.message-row.user .message-stack {
  align-items: flex-end;
}

/* Feeling / umore */
.feeling-card {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
}
.feeling-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 10px;
}
.feeling-head strong {
  font-size: 0.92rem;
}
.feeling-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.feeling-bar-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.feeling-bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #6b52e8, var(--accent), #f472b6);
  transition: width 0.45s ease;
}
.feeling-caption {
  margin: 8px 0 0;
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Guida messaggi */
.msg-guide {
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.msg-guide-toggle {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: 0;
  padding: 8px 14px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.msg-guide-toggle:hover {
  color: var(--text);
  filter: none;
}
.msg-guide-body {
  padding: 0 14px 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
}
.msg-guide-body[hidden] {
  display: none;
}
.msg-guide-body p {
  margin: 0 0 6px;
}
.msg-guide-body code {
  color: var(--accent);
  font-size: 0.8rem;
}
.msg-notice-user-thought {
  background: rgba(167, 139, 250, 0.12);
  border-color: rgba(167, 139, 250, 0.35);
  color: #c4b5fd;
  align-self: flex-end;
}
.system-note-warn .message-bubble {
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
  color: #fcd34d;
}
