:root {
  /* Fixed dark theme on purpose: this is the app's own identity (like most
     18+ chat-companion apps), not something that should flip to white when
     the user's Telegram happens to be in light mode. app.js no longer
     overrides these from Telegram.WebApp.themeParams. */
  --tg-bg: #131318;
  --tg-text: #f2f2f7;
  --tg-hint: #9797a6;
  --tg-link: #a78bfa;
  --tg-button: #8b5cf6;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #1e1e26;

  /* Fixed accent palette, independent of the base theme above -- this is
     what gives the app its own colorful personality instead of looking
     like a plain grey system form. */
  --accent-violet: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-cyan: #06b6d4;
  --accent-orange: #f59e0b;
  --accent-gradient: linear-gradient(135deg, var(--accent-violet), var(--accent-pink));
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  /* Soft, fixed-hue wash behind everything; content itself sits on
     var(--tg-secondary-bg) cards so text contrast still comes from
     Telegram's own theme, not from this decorative backdrop. */
  background:
    radial-gradient(circle at 15% 0%, rgba(139, 92, 246, 0.16), transparent 55%),
    radial-gradient(circle at 100% 20%, rgba(236, 72, 153, 0.14), transparent 50%),
    var(--tg-bg);
  background-attachment: fixed;
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.screen[hidden] {
  display: none;
}

.screen {
  animation: fade-in 0.25s ease both;
}

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

.title {
  font-size: 26px;
  font-weight: 800;
  margin: 4px 0 2px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.subtitle {
  font-size: 14px;
  color: var(--tg-hint);
  margin: 0 0 16px;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

#search-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-secondary-bg);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 16px;
}

#search-input:focus {
  outline: 2px solid var(--accent-violet);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 6px 16px rgba(139, 92, 246, 0.35);
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 3px 8px rgba(139, 92, 246, 0.3);
}

.btn-full {
  display: block;
  width: 100%;
  margin-top: 16px;
  padding: 12px 16px;
  font-size: 16px;
}

.btn-back {
  background: transparent;
  color: var(--accent-pink);
  padding: 8px 0;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 700;
}

.status {
  color: var(--tg-hint);
  font-size: 14px;
  margin: 8px 0 16px;
  line-height: 1.4;
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.result-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 12px;
  background: var(--tg-secondary-bg);
  cursor: pointer;
  text-align: left;
  border: 2px solid transparent;
  width: 100%;
  color: var(--tg-text);
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.result-card:active {
  transform: scale(0.98);
  border-color: var(--accent-violet);
}

.result-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--accent-gradient);
}

.result-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.result-info {
  min-width: 0;
}

.result-name {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-anime {
  font-size: 13px;
  color: var(--tg-hint);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-card {
  border-radius: 20px;
  overflow: hidden;
  background: var(--tg-secondary-bg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  margin-bottom: 8px;
}

.preview-media {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  background: linear-gradient(160deg, var(--accent-violet), var(--accent-pink) 55%, var(--accent-orange));
  overflow: hidden;
}

.preview-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
}

.preview-media-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 45%;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
  pointer-events: none;
}

.preview-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 16px;
  color: #ffffff;
}

.preview-name {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 8px;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 12px;
  font-weight: 600;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(4px);
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.notes-label {
  display: block;
  font-size: 14px;
  color: var(--tg-hint);
  margin: 12px 0 6px;
}

.notes-textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--tg-secondary-bg);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
}

.notes-textarea:focus {
  outline: 2px solid var(--accent-violet);
}

.segmented-control {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: var(--tg-secondary-bg);
}

.segment {
  flex: 1;
  border: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
  background: transparent;
  color: var(--tg-hint);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.segment.active {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}

/* Hub screen: character cards with compact per-card actions (Select/Edit/
   Delete) instead of a single big tap target like .result-card. */

.char-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: var(--tg-secondary-bg);
}

.char-card-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.char-card-actions {
  display: flex;
  gap: 6px;
}

.char-action-btn {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.08);
  color: var(--tg-text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.15s ease, background 0.15s ease;
}

.char-action-btn:active {
  transform: scale(0.96);
}

.char-action-danger {
  background: rgba(236, 72, 153, 0.18);
  color: var(--accent-pink);
}

.char-card-confirm {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 8px;
}

.char-confirm-text {
  font-size: 13px;
  color: var(--tg-hint);
  margin: 0 0 8px;
}

.char-confirm-actions {
  display: flex;
  gap: 6px;
}
