/* ── Max Friend AI · Глобальные стили мини-приложения ── */

:root {
  --bg:        #0b0d1a;
  --bg-soft:   #11142a;
  --card:      #161a36;
  --card-2:    #1d2147;
  --border:    rgba(255,255,255,0.06);
  --text:      #ecedf5;
  --muted:     #8b91b8;
  --accent:    #6c5ce7;     /* фиолет */
  --accent-2:  #00d2c7;     /* мятный */
  --accent-3:  #ff6b9d;     /* розовый */
  --warn:      #ffb84f;
  --danger:    #ff5470;
  --shadow:    0 12px 40px rgba(0,0,0,0.45);
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 10px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.55;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 80% 60% at 50% -10%, rgba(108,92,231,0.25), transparent 60%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(0,210,199,0.12), transparent 60%),
    radial-gradient(ellipse 60% 40% at 0% 100%, rgba(255,107,157,0.10), transparent 60%);
  background-attachment: fixed;
  padding-bottom: 90px;
}

a { color: var(--accent-2); text-decoration: none; }

/* ── Хедер ── */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(11,13,26,0.85);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-header .logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 6px 20px rgba(108,92,231,0.4);
}
.app-header .title {
  font-size: 17px; font-weight: 700;
}
.app-header .subtitle {
  font-size: 12px; color: var(--muted);
}
.app-header .back {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--card);
  display: grid; place-items: center;
  cursor: pointer;
  margin-right: 4px;
  transition: 0.15s;
}
.app-header .back:active { transform: scale(0.92); }

/* ── Контейнер ── */
.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Карточки ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card.gradient {
  background: linear-gradient(135deg, var(--card-2) 0%, var(--card) 100%);
  position: relative;
  overflow: hidden;
}
.card.gradient::before {
  content: '';
  position: absolute;
  top: -50%; right: -20%;
  width: 250px; height: 250px;
  background: radial-gradient(circle, rgba(108,92,231,0.35), transparent 70%);
  pointer-events: none;
}
.card h3 {
  margin: 0 0 12px 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Hero на главной ── */
.hero {
  text-align: center;
  padding: 28px 18px 20px;
}
.hero .avatar {
  width: 96px; height: 96px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2), var(--accent-3));
  display: grid; place-items: center;
  font-size: 48px;
  box-shadow: 0 12px 40px rgba(108,92,231,0.5);
  position: relative;
}
.hero .avatar::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.08);
  animation: pulse 2.5s infinite;
}
@keyframes pulse {
  0%   { transform: scale(1);   opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}
.hero h1 {
  font-size: 28px;
  margin: 0 0 8px;
  font-weight: 800;
  background: linear-gradient(135deg, #fff, #c5c8e8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.hero .lead {
  color: var(--muted);
  margin: 0;
  font-size: 15px;
}

/* ── Кнопки ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: var(--r-md);
  background: var(--card-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--border);
  cursor: pointer;
  width: 100%;
  transition: 0.15s;
  font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  box-shadow: 0 8px 22px rgba(108,92,231,0.35);
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger {
  background: rgba(255,84,112,0.12);
  border: 1px solid rgba(255,84,112,0.3);
  color: var(--danger);
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--border);
}
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }

/* ── Меню-сетка ── */
.menu-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}
.menu-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 18px 16px;
  cursor: pointer;
  transition: 0.2s;
  position: relative;
  overflow: hidden;
}
.menu-tile:active { transform: scale(0.97); }
.menu-tile .icon {
  font-size: 32px;
  margin-bottom: 12px;
  display: inline-block;
}
.menu-tile .label {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 4px;
}
.menu-tile .desc {
  font-size: 12px;
  color: var(--muted);
}
.menu-tile.accent::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(108,92,231,0.15), transparent 60%);
  pointer-events: none;
}

/* ── Поля ввода ── */
.input, .textarea, .select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: 0.15s;
  outline: none;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(108,92,231,0.2);
}
.textarea { resize: vertical; min-height: 100px; }
.label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

/* ── Switch ── */
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
}
.switch + .switch { border-top: 1px solid var(--border); }
.switch .text strong { display: block; font-size: 15px; }
.switch .text small { color: var(--muted); font-size: 12px; }
.toggle {
  width: 50px; height: 28px;
  background: var(--bg-soft);
  border-radius: 50px;
  position: relative;
  cursor: pointer;
  transition: 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: '';
  position: absolute;
  width: 22px; height: 22px;
  background: var(--text);
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: 0.25s;
}
.toggle.on { background: var(--accent-2); }
.toggle.on::after { left: 25px; background: white; }

/* ── Чипы ── */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  padding: 8px 14px;
  border-radius: 50px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  font-size: 14px;
  cursor: pointer;
  transition: 0.15s;
}
.chip:active { transform: scale(0.93); }
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

/* ── Стат-блоки ── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 14px;
  text-align: center;
}
.stat-tile .num {
  font-size: 22px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.stat-tile .lbl {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

/* ── Список personalities ── */
.pers-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.pers-card {
  background: var(--card);
  border: 2px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px;
  cursor: pointer;
  transition: 0.18s;
  text-align: center;
}
.pers-card:active { transform: scale(0.96); }
.pers-card.active {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(108,92,231,0.18), var(--card));
  box-shadow: 0 8px 22px rgba(108,92,231,0.25);
}
.pers-card .emoji { font-size: 32px; margin-bottom: 6px; }
.pers-card .name { font-weight: 700; font-size: 14px; }

/* ── История чата ── */
.msg-list { display: flex; flex-direction: column; gap: 10px; }
.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), #5a4dd8);
  color: white;
  border-bottom-right-radius: 6px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.msg .ts {
  display: block;
  font-size: 10px;
  color: var(--muted);
  margin-top: 4px;
  opacity: 0.7;
}

/* ── Чат-композер ── */
.composer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(11,13,26,0.92);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}
.composer .input {
  flex: 1;
  background: var(--card);
}
.composer .send {
  width: 48px; height: 48px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(108,92,231,0.35);
}
.composer .send:active { transform: scale(0.92); }

/* ── Студия картинок ── */
.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.gallery img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: 0.15s;
}
.gallery img:active { transform: scale(0.97); }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--r-lg);
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  transition: 0.15s;
  background: rgba(255,255,255,0.02);
}
.dropzone:hover { border-color: var(--accent); color: var(--text); }
.dropzone .dz-icon { font-size: 40px; display: block; margin-bottom: 10px; }

/* ── Спиннер ── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 14px; }
.mt-lg { margin-top: 24px; }

/* ── Toasts ── */
#toast {
  position: fixed;
  top: 20px; left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  z-index: 1000;
  transition: transform 0.3s;
  box-shadow: var(--shadow);
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.ok    { border-color: var(--accent-2); }
#toast.err   { border-color: var(--danger); }

/* ── Утилитарное ── */
hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.flex { display: flex; gap: 10px; align-items: center; }
.between { justify-content: space-between; }
.grow { flex: 1; }
