:root {
  --bg: #09090f;
  --bg-elevated: #12121a;
  --surface: #1a1a26;
  --surface-hover: #222230;
  --text: #f4f4f8;
  --muted: #8b8b9e;
  --accent: #7c6cff;
  --accent-strong: #6554f5;
  --user-bubble: linear-gradient(135deg, #3d3566, #2a2548);
  --bot-bubble: #1e1e2c;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 16px;
  --radius-lg: 20px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(124, 108, 255, 0.15), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(255, 80, 120, 0.06), transparent),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(9, 9, 15, 0.8);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}

.topbar h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn:hover {
  background: var(--surface-hover);
  border-color: rgba(255, 255, 255, 0.14);
}

.text-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.text-btn:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.18);
}

/* ── Screens ── */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 20px 18px 28px;
}

.hidden {
  display: none !important;
}

.hero {
  margin-bottom: 20px;
}

.hero-label {
  margin: 0 0 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}

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

.search-wrap {
  position: relative;
  margin-bottom: 18px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 16px 13px 44px;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search-input:focus {
  outline: none;
  border-color: rgba(124, 108, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 108, 255, 0.12);
}

#search-input::placeholder {
  color: var(--muted);
}

.no-results {
  text-align: center;
  color: var(--muted);
  padding: 32px 16px;
  font-size: 0.95rem;
}

/* ── Character grid — big portrait cards ── */
.character-list {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(2, 1fr);
}

.character-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s;
  text-align: left;
  color: var(--text);
  display: block;
  font: inherit;
}

.character-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow);
}

.character-visual {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  min-height: 200px;
  background: #0a0a10;
}

.character-avatar {
  width: 100%;
  height: 100%;
  border-radius: 0;
  object-fit: cover;
  object-position: top center;
  display: block;
  border: none;
  box-shadow: none;
}

.character-name-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 28px 12px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.45) 55%, transparent 100%);
  pointer-events: none;
}

.character-card h2 {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Themed cards via CSS variables */
.character-card[class*="theme-"] {
  background: linear-gradient(135deg, var(--card-bg1), var(--card-bg2) 50%, var(--card-bg3));
  border: 2px solid var(--card-accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 4px 16px var(--card-glow);
}

.character-card[class*="theme-"]:hover {
  border-color: var(--card-accent-hover);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 8px 28px var(--card-glow-hover);
}

.character-card[class*="theme-"] h2 {
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

.character-card[class*="theme-"] .character-visual::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--card-accent), var(--card-accent2));
}

.theme-yakuza {
  --card-bg1: #2b2b2b; --card-bg2: #5e5e5e; --card-bg3: #3d3d3d;
  --card-accent: #c8102e; --card-accent-hover: #ff2a3d; --card-accent2: #8b0000;
  --card-glow: rgba(200, 16, 46, 0.2); --card-glow-hover: rgba(200, 16, 46, 0.35);
}
.theme-yakuza .character-avatar { object-position: 18% top; }

.theme-sadistic-beauty {
  --card-bg1: #0b0b0d; --card-bg2: #3a3228; --card-bg3: #141218;
  --card-accent: #eb0014; --card-accent-hover: #ff3347; --card-accent2: #e8e8ec;
  --card-glow: rgba(235, 0, 20, 0.22); --card-glow-hover: rgba(235, 0, 20, 0.38);
}

.theme-elden-ring {
  --card-bg1: #1a1812; --card-bg2: #2e3a28; --card-bg3: #151510;
  --card-accent: #c9a227; --card-accent-hover: #e8c547; --card-accent2: #4a6b3a;
  --card-glow: rgba(201, 162, 39, 0.18); --card-glow-hover: rgba(201, 162, 39, 0.32);
}

.theme-pokemon {
  --card-bg1: #1a1520; --card-bg2: #3d2e4a; --card-bg3: #12101a;
  --card-accent: #e8b923; --card-accent-hover: #ffd54f; --card-accent2: #7b5ea7;
  --card-glow: rgba(232, 185, 35, 0.2); --card-glow-hover: rgba(232, 185, 35, 0.35);
}

.theme-chainsaw-man {
  --card-bg1: #1a1210; --card-bg2: #3d2018; --card-bg3: #120e0c;
  --card-accent: #d4a017; --card-accent-hover: #f0c040; --card-accent2: #8b1a1a;
  --card-glow: rgba(212, 160, 23, 0.2); --card-glow-hover: rgba(212, 160, 23, 0.35);
}

.theme-jujutsu-kaisen {
  --card-bg1: #0e1228; --card-bg2: #1a2860; --card-bg3: #0a0e1e;
  --card-accent: #6b8cff; --card-accent-hover: #8aa4ff; --card-accent2: #9b4dff;
  --card-glow: rgba(107, 140, 255, 0.2); --card-glow-hover: rgba(107, 140, 255, 0.35);
}
.theme-jujutsu-kaisen .character-avatar { object-position: 50% 8%; }

.theme-mj {
  --card-bg1: #0d0d0d; --card-bg2: #1a1a1a; --card-bg3: #0a0a0a;
  --card-accent: #c9a227; --card-accent-hover: #e8c547; --card-accent2: #8b1a1a;
  --card-glow: rgba(201, 162, 39, 0.2); --card-glow-hover: rgba(201, 162, 39, 0.35);
}

.theme-sonic {
  --card-bg1: #121218; --card-bg2: #2a1a2a; --card-bg3: #0e0e14;
  --card-accent: #e82020; --card-accent-hover: #ff4040; --card-accent2: #f0c020;
  --card-glow: rgba(232, 32, 32, 0.2); --card-glow-hover: rgba(232, 32, 32, 0.35);
}

.theme-spiderman {
  --card-bg1: #0e1428; --card-bg2: #1a2860; --card-bg3: #0a0e1a;
  --card-accent: #e82020; --card-accent-hover: #ff3838; --card-accent2: #2060c0;
  --card-glow: rgba(232, 32, 32, 0.2); --card-glow-hover: rgba(232, 32, 32, 0.35);
}

.theme-jojo {
  --card-bg1: #1a1028; --card-bg2: #3d2060; --card-bg3: #100818;
  --card-accent: #f0c020; --card-accent-hover: #ffe060; --card-accent2: #8b2080;
  --card-glow: rgba(240, 192, 32, 0.2); --card-glow-hover: rgba(240, 192, 32, 0.35);
}

.theme-brawl-stars {
  --card-bg1: #1a1018; --card-bg2: #4a1828; --card-bg3: #120810;
  --card-accent: #e82050; --card-accent-hover: #ff3868; --card-accent2: #f0c020;
  --card-glow: rgba(232, 32, 80, 0.2); --card-glow-hover: rgba(232, 32, 80, 0.35);
}

.theme-dragon-ball {
  --card-bg1: #1a1810; --card-bg2: #4a3018; --card-bg3: #100e08;
  --card-accent: #f08020; --card-accent-hover: #ffa040; --card-accent2: #2060c0;
  --card-glow: rgba(240, 128, 32, 0.2); --card-glow-hover: rgba(240, 128, 32, 0.35);
}

.theme-death-note {
  --card-bg1: #0e0e10; --card-bg2: #1a1a22; --card-bg3: #08080a;
  --card-accent: #c0c0c8; --card-accent-hover: #e8e8f0; --card-accent2: #8b1a1a;
  --card-glow: rgba(139, 26, 26, 0.2); --card-glow-hover: rgba(139, 26, 26, 0.35);
}

.theme-monster {
  --card-bg1: #1a1814; --card-bg2: #3a3428; --card-bg3: #100e0c;
  --card-accent: #c8b898; --card-accent-hover: #e0d0b0; --card-accent2: #606058;
  --card-glow: rgba(200, 184, 152, 0.15); --card-glow-hover: rgba(200, 184, 152, 0.28);
}

/* ── Chat ── */
.messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  scroll-behavior: smooth;
}

.message {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-size: 0.95rem;
  animation: fadeUp 0.2s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message .label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 5px;
}

.message-image {
  display: block;
  width: 100%;
  max-width: 320px;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.chat-hint {
  margin: 0 0 12px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.chat-hint code {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.72rem;
  color: var(--text);
}

.chat-form {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.chat-form input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 18px;
  font: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-form input:focus {
  outline: none;
  border-color: rgba(124, 108, 255, 0.5);
  box-shadow: 0 0 0 3px rgba(124, 108, 255, 0.12);
}

.chat-form button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.chat-form button svg {
  width: 20px;
  height: 20px;
}

.chat-form button:hover {
  background: var(--accent-strong);
}

.chat-form button:active {
  transform: scale(0.96);
}

.chat-form button:disabled,
.chat-form input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Feedback ── */
.loading {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px 18px;
  border-radius: 999px;
}

.loading-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 4px;
}

.loading-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.15s; }
.loading-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

.error {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2a1218;
  border: 1px solid #ff6b7a;
  color: #ffd7dc;
  padding: 12px 18px;
  border-radius: 14px;
  max-width: 90%;
  font-size: 0.9rem;
}

@media (min-width: 560px) {
  .character-list {
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
  }

  .character-visual {
    min-height: 240px;
  }

  .character-card h2 {
    font-size: 0.85rem;
  }
}

@media (min-width: 860px) {
  .character-list {
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
  }

  .character-visual {
    min-height: 260px;
  }
}

/* ── Auth ── */
.auth-screen {
  justify-content: center;
  padding: 24px 18px 48px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.auth-title {
  margin: 8px 0 6px;
  font-size: 1.45rem;
}

.auth-sub {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.5;
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.auth-tab {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 12px;
  padding: 10px;
  cursor: pointer;
  font: inherit;
}

.auth-tab.active {
  background: rgba(124, 108, 255, 0.15);
  border-color: rgba(124, 108, 255, 0.45);
  color: var(--text);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-form input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
}

.auth-form input:focus {
  outline: none;
  border-color: rgba(124, 108, 255, 0.6);
}

.primary-btn {
  margin-top: 6px;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.auth-hint {
  margin-top: 14px;
  font-size: 0.82rem;
  color: #ffd7a8;
  line-height: 1.45;
}

.auth-link-btn {
  margin-top: 12px;
}

.verify-code-box {
  margin: 0 0 18px;
  padding: 18px;
  text-align: center;
  background: rgba(124, 108, 255, 0.12);
  border: 1px solid rgba(124, 108, 255, 0.35);
  border-radius: 14px;
}

.verify-code-label {
  margin: 0 0 8px;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.verify-code-display {
  margin: 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  color: var(--text);
}

.verify-code-note {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

/* ── General AI card ── */
.general-ai-card {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  padding: 16px 18px;
  background: linear-gradient(135deg, rgba(124, 108, 255, 0.18), rgba(80, 120, 255, 0.12));
  border: 1px solid rgba(124, 108, 255, 0.35);
  border-radius: var(--radius-lg);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.general-ai-card:hover {
  transform: translateY(-2px);
  border-color: rgba(124, 108, 255, 0.55);
  box-shadow: 0 8px 28px rgba(124, 108, 255, 0.15);
}

.general-ai-icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(124, 108, 255, 0.25);
  font-size: 1.2rem;
  flex-shrink: 0;
}

.general-ai-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.general-ai-text strong {
  font-size: 1rem;
}

.general-ai-text span {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.35;
}

.general-ai-arrow {
  width: 20px;
  height: 20px;
  color: var(--muted);
  flex-shrink: 0;
}

/* ── Profile ── */
.profile-card {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.profile-title {
  margin: 8px 0 6px;
  font-size: 1.45rem;
}

.profile-level {
  display: inline-block;
  margin: 0 0 16px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(124, 108, 255, 0.15);
  border: 1px solid rgba(124, 108, 255, 0.35);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
}

.captcha-wrap {
  min-height: 65px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.captcha-missing {
  margin: 0;
  font-size: 0.82rem;
  color: #ffd7a8;
  text-align: center;
  line-height: 1.4;
}

.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 20px 0 24px;
}

.profile-avatar-preview {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3d3566, #2a2548);
  border: 2px solid rgba(124, 108, 255, 0.4);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.profile-avatar-preview span {
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
}

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

.profile-avatar-upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.profile-avatar-upload:hover {
  border-color: rgba(124, 108, 255, 0.5);
  background: var(--surface-hover);
}

.auth-form textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text);
  font: inherit;
  resize: vertical;
  min-height: 96px;
}

.auth-form textarea:focus {
  outline: none;
  border-color: rgba(124, 108, 255, 0.6);
}

.auth-form input:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.field-hint {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: right;
}

.profile-logout-btn {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
}
