/* Оформление мини-приложения Vibe.
 *
 * Принципы:
 *   - светлая и тёмная темы (как в MAX);
 *   - безопасные зоны телефона: «чёлка» сверху, жесты снизу;
 *   - крупные кнопки под палец, минимум мелкого текста;
 *   - карточка занимает всё окно, как в Tinder — свайпать удобно.
 */

:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f7;
  --card: #ffffff;
  --text: #10131a;
  --text-dim: #6b7280;
  --line: #e6e8ec;
  --accent: #2b6cff;
  --accent-soft: #eaf0ff;
  --like: #ff4d6d;
  --nope: #6b7280;
  --super: #ffb020;
  --bubble-mine: #2b6cff;
  --bubble-mine-text: #ffffff;
  --bubble-theirs: #f0f1f4;
  --danger: #d33;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1015;
    --bg-soft: #171a21;
    --card: #171a21;
    --text: #eef1f6;
    --text-dim: #9aa3b2;
    --line: #262b35;
    --accent: #6a9bff;
    --accent-soft: #1b2334;
    --like: #ff5f7d;
    --nope: #9aa3b2;
    --super: #ffc043;
    --bubble-mine: #3d6fff;
    --bubble-mine-text: #ffffff;
    --bubble-theirs: #22262f;
    --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg-soft);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

/* Верхняя панель. Отступы сверху — под «чёлку», иначе заголовок
   уезжает под статус-бар. */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 10;
}

.topbar .titles { flex: 1; min-width: 0; }

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.subtitle {
  color: var(--text-dim);
  font-size: 12px;
  min-height: 14px;
}

.back, .reload {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
  flex: 0 0 auto;
}
.reload { font-size: 20px; }
.back:hover, .reload:hover { background: var(--accent-soft); }

/* Экран занимает всё место между панелью и вкладками. */
.screen {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 8px 0 calc(env(safe-area-inset-bottom) + 8px);
  min-height: 0;
}

.screen.chat-open {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

.loader, .empty, .error {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-dim);
}
.empty .big { font-size: 52px; margin-bottom: 6px; }
.empty h2 { margin: 0 0 8px; font-size: 19px; color: var(--text); }
.empty p { margin: 0 auto 18px; max-width: 300px; }
.error { color: var(--danger); }

/* Нижняя навигация */
.tabs {
  display: flex;
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 11px;
  padding: 8px 0 7px;
  cursor: pointer;
}
.tab span { font-size: 21px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tab.active { color: var(--accent); font-weight: 600; }
.tab.active span { filter: none; opacity: 1; }

/* ------------------------------------------------------------------ лента */

/* Высота колоды. Считаем не «на глаз»: из экрана вычитаются верхняя
   панель, нижняя навигация и ряд кнопок действий. Раньше стояло 168px —
   кружки ❤️/👎 заезжали под навигацию и их нельзя было нажать. */
.deck {
  position: relative;
  height: calc(100dvh - 228px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  min-height: 300px;
  margin: 4px 12px 0;
}

.card {
  position: absolute;
  inset: 0;
  border-radius: 20px;
  overflow: hidden;
  background: var(--bg-soft);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
  transform-origin: 50% 100%;
  will-change: transform;
  touch-action: pan-y;
}
.card.second { transform: translateY(10px) scale(.965); z-index: 2; }
.card.third { transform: translateY(20px) scale(.93); z-index: 1; }
.card.top { z-index: 3; }
.card.fly-right { transition: transform .22s ease, opacity .22s ease; transform: translate(120%, -20px) rotate(18deg); opacity: 0; }
.card.fly-left { transition: transform .22s ease, opacity .22s ease; transform: translate(-120%, -20px) rotate(-18deg); opacity: 0; }

.card-img, .card .ph-fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ph-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 84px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, #6a9bff, #b06ab3);
}
/* Аватар и фото анкеты — не на весь экран, а в своём круге/квадрате. */
.avatar.ph-fallback,
.me-photo.ph-fallback {
  position: static;
  width: 100%;
  height: 100%;
  background: var(--accent-soft);
  color: var(--accent);
}
.avatar.ph-fallback { font-size: 20px; }
.me-photo.ph-fallback { font-size: 34px; }

.card-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,.10) 0%, transparent 28%,
              transparent 45%, rgba(0,0,0,.78) 100%);
  pointer-events: none;
}

.card-info {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 18px 18px 20px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,.35);
}

.card-name { font-size: 24px; font-weight: 700; line-height: 1.2; }
.card-city { font-size: 14px; opacity: .9; margin-top: 2px; }
.card-about {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 20px;
  background: rgba(255,255,255,.18);
  backdrop-filter: blur(4px);
  text-shadow: none;
}

.card-menu {
  position: absolute;
  top: 12px; right: 12px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.32);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  padding-bottom: 8px;
  cursor: pointer;
}

.swipe-label {
  position: absolute;
  top: 26px;
  padding: 6px 12px;
  border: 2px solid #fff;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  background: rgba(0,0,0,.15);
}
.swipe-label.like { left: 18px; transform: rotate(-12deg); border-color: var(--like); color: #ffd9e0; }
.swipe-label.nope { right: 18px; transform: rotate(12deg); border-color: #fff; }

.actions {
  display: flex;
  justify-content: center;
  gap: 26px;
  padding: 14px 12px 4px;
}

.act {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
}
.act span {
  width: 62px; height: 62px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  background: var(--card);
  box-shadow: 0 6px 18px rgba(0,0,0,.14);
  transition: transform .12s ease;
}
.act:active span { transform: scale(.92); }
.act.like span { box-shadow: 0 6px 20px rgba(255,77,109,.35); }
.act.super span { width: 52px; height: 52px; font-size: 23px; box-shadow: 0 6px 18px rgba(255,176,32,.35); }
.act.nope span { width: 52px; height: 52px; font-size: 22px; }

.deck-empty { padding: 40px 24px; text-align: center; color: var(--text-dim); }
.deck-empty .big { font-size: 56px; }
.deck-empty h2 { color: var(--text); margin: 6px 0 8px; }
.deck-empty p { max-width: 300px; margin: 0 auto 18px; }

/* ------------------------------------------------------------------- чаты */

.chat {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.chat:active { background: var(--accent-soft); }

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex: 0 0 48px;
  object-fit: cover;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--accent);
  font-weight: 600;
}

.chat-body { flex: 1; min-width: 0; }

.chat-name {
  font-weight: 600;
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge { font-size: 13px; }

.chat-preview {
  color: var(--text-dim);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-time { color: var(--text-dim); font-size: 12px; flex: 0 0 auto; }

.closed-tag {
  font-size: 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 1px 6px;
}

.msgs {
  padding: 12px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}
.msgs .empty.small { padding: 32px 24px; }

.msg {
  max-width: 78%;
  padding: 8px 12px;
  border-radius: 16px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg.mine {
  align-self: flex-end;
  background: var(--bubble-mine);
  color: var(--bubble-mine-text);
  border-bottom-right-radius: 4px;
}
.msg.theirs {
  align-self: flex-start;
  background: var(--bubble-theirs);
  border-bottom-left-radius: 4px;
}
.msg.photo { color: var(--text-dim); font-style: italic; }

.day {
  align-self: center;
  font-size: 12px;
  color: var(--text-dim);
  background: var(--bg-soft);
  padding: 3px 10px;
  border-radius: 10px;
  margin: 8px 0;
}

.person-head {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.person-head .meta { color: var(--text-dim); font-size: 13px; margin-top: 2px; }

.composer {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: var(--card);
  flex: 0 0 auto;
}
.composer input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  border-radius: 20px;
  padding: 10px 14px;
  font: inherit;
  outline: none;
}
.composer input:focus { border-color: var(--accent); }
.send {
  width: 42px; height: 42px;
  flex: 0 0 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.send:disabled { opacity: .5; }

.moderation-note {
  font-size: 11px;
  color: var(--text-dim);
  text-align: center;
  padding: 2px 12px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--card);
  flex: 0 0 auto;
}

/* ------------------------------------------------------------- моя анкета */

.me-head {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 8px 16px 14px;
}
.me-photo {
  width: 84px; height: 84px;
  flex: 0 0 84px;
  border-radius: 20px;
  overflow: hidden;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  color: var(--accent);
  font-weight: 700;
}
.me-photo img { width: 100%; height: 100%; object-fit: cover; }
.me-title { min-width: 0; }
.me-name { font-size: 20px; font-weight: 700; }
.me-title .meta { color: var(--text-dim); font-size: 13px; margin-top: 2px; }
.pill {
  display: inline-block;
  margin-top: 6px;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--bg-soft);
  color: var(--text-dim);
}
.pill.on { background: #e6f7ec; color: #1a7f43; }
.pill.off { background: #fff1e0; color: #a45b00; }
@media (prefers-color-scheme: dark) {
  .pill.on { background: #10301f; color: #74d99f; }
  .pill.off { background: #33240d; color: #ffc06a; }
}

.block {
  padding: 14px 16px;
  border-top: 8px solid var(--bg-soft);
}
.block-title { font-weight: 700; font-size: 15px; margin-bottom: 10px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-soft);
  border: 2px solid transparent;
  cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.main { border-color: var(--accent); }
.thumb-tag {
  position: absolute;
  left: 5px; bottom: 5px;
  font-size: 10px;
  background: rgba(0,0,0,.6);
  color: #fff;
  border-radius: 8px;
  padding: 2px 7px;
}
.thumb-del {
  position: absolute;
  top: 4px; right: 4px;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 13px;
  cursor: pointer;
}
.thumb.add {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 2px dashed var(--line);
  color: var(--text-dim);
  font-size: 26px;
  font-weight: 400;
}
.thumb.add span { font-size: 11px; }

.field { display: block; margin-bottom: 12px; }
.field span {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.field input, .field textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  outline: none;
  resize: vertical;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  cursor: pointer;
}
.switch-row > span:first-child { flex: 1; }
.switch-row input { display: none; }
.switch {
  width: 48px; height: 28px;
  flex: 0 0 48px;
  border-radius: 20px;
  background: var(--line);
  position: relative;
  transition: background .18s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.25);
  transition: transform .18s ease;
}
.switch-row input:checked + .switch { background: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(20px); }

.hintline, .note {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 8px;
}
.note {
  margin: 0 16px 4px;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: 12px;
  color: var(--text);
}

.stats {
  display: flex;
  gap: 8px;
  text-align: center;
}
.stat {
  flex: 1;
  background: var(--bg-soft);
  border-radius: 14px;
  padding: 10px 4px;
}
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 11px; color: var(--text-dim); }

.footer-note {
  padding: 4px 16px calc(env(safe-area-inset-bottom) + 20px);
  color: var(--text-dim);
  font-size: 12px;
}

/* --------------------------------------------------------- модалка и тост */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: 12px;
  padding-bottom: calc(env(safe-area-inset-bottom) + 12px);
}
.modal[hidden] { display: none; }

.modal-box {
  background: var(--card);
  color: var(--text);
  border-radius: 20px;
  padding: 18px;
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.modal-box h2 { margin: 0 0 10px; font-size: 19px; }
.modal-body p { margin: 0 0 10px; }
.modal-body .muted { color: var(--text-dim); }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.modal-actions .btn { width: 100%; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(20, 22, 28, .94);
  color: #fff;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: 14px;
  z-index: 120;
  max-width: 88vw;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
}
.toast[hidden] { display: none; }
