:root {
  --ink: #f5f4f8;
  --muted: #a3a0b2;
  --line: #34323d;
  --bg: #141317;
  --bg2: #2a1f4d;
  --card: #232228;
  --accent: #ff2e93;
  --accent-soft: rgba(255, 46, 147, .14);
  --btn-color: #ff2e93;
  --btn-ink: #ffffff;
  --btn-ink-off: #8b8899;
  --radius: 18px;
  --track: #34323d;
  --photo-grad: linear-gradient(150deg, #3a2b4d, #2a2733 55%, #43223a);
  --bg-fade: linear-gradient(to top, rgba(20, 19, 23, .98) 55%, rgba(20, 19, 23, 0));
  --badge-bg: rgba(20, 19, 23, .72);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 18px 40px -24px rgba(0, 0, 0, .9);
}

/* светлая тема включается из админки */
body[data-dark="0"] {
  --ink: #14131a;
  --muted: #6b6a75;
  --line: #e7e5e0;
  --card: #ffffff;
  --accent-soft: rgba(108, 92, 231, .13);
  --track: #eceaf0;
  --photo-grad: linear-gradient(150deg, #efeaff, #f6f1ff 55%, #ffeef4);
  --bg-fade: linear-gradient(to top, rgba(247, 246, 243, .98) 55%, rgba(247, 246, 243, 0));
  --badge-bg: rgba(255, 255, 255, .88);
  --btn-ink-off: #8b8899;
  --shadow: 0 1px 2px rgba(20, 19, 26, .04), 0 12px 32px -18px rgba(20, 19, 26, .25);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background .35s ease, color .35s ease;
}

/* фон-фото из админки: на широком экране — горизонтальный кадр,
   на вертикальном телефоне — портретный, чтобы не резалось по живому */
body.has-bg {
  background-image: var(--bg-scrim), var(--bg-img);
  background-size: cover, cover;
  background-position: center center, center center;
  background-repeat: no-repeat, no-repeat;
}
@media (max-aspect-ratio: 3 / 4) {
  body.has-bg { background-image: var(--bg-scrim), var(--bg-img-portrait); }
}

/* ---------- слой фоновых эффектов ---------- */
#fx {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
}
.fx-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: .5;
  will-change: transform;
}
.fx-bubble {
  position: absolute;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, .8), rgba(255, 255, 255, .04) 62%), var(--accent);
  opacity: .2;
  will-change: transform;
}
.fx-star {
  position: absolute;
  border-radius: 50%;
  background: var(--accent);
  opacity: .35;
  animation: twinkle 3.4s ease-in-out infinite;
  will-change: transform;
}
@keyframes twinkle {
  0%, 100% { opacity: .12; transform: scale(.7); }
  50% { opacity: .55; transform: scale(1.15); }
}
.fx-cat {
  position: absolute;
  bottom: 6px;
  font-size: 26px;
  line-height: 1;
  opacity: .85;
  will-change: transform;
}
.fx-paw { position: absolute; font-size: 15px; opacity: .25; will-change: transform; }

.wrap {
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 20px 56px;
}

/* ---------- шапка ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--btn-color);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 7px 14px;
}
.tag .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--btn-color);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.tag.closed { color: #ffc247; background: rgba(255, 194, 71, .14); }
.tag.closed .dot { background: #ffc247; box-shadow: 0 0 0 3px rgba(255, 194, 71, .14); }

h1 {
  text-align: center;
  font-family: var(--title-font, inherit);
  font-size: clamp(26px, 5.2vw, 40px);
  line-height: 1.12;
  letter-spacing: -.03em;
  margin: 16px 0 8px;
  font-weight: 800;
}

.lead {
  color: var(--muted);
  font-size: clamp(13.5px, 2.4vw, 15.5px);
  line-height: 1.5;
  margin: 0 auto 18px;
  max-width: 52ch;
  text-align: center;
}

.tag-row { text-align: center; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  justify-content: center;
}
.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.chip b { font-size: 15px; color: var(--ink); font-variant-numeric: tabular-nums; }

/* ---------- пользователь ---------- */
.user-bar {
  display: flex;
  justify-content: center;
  margin: 12px 0 6px;
}
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px 7px 8px;
  font-size: 13.5px;
  font-weight: 600;
  transition: border-color .15s ease, transform .15s ease;
}
.user-chip:hover { border-color: var(--btn-color); }
.user-chip img,
.user-chip .ava-empty {
  width: 28px; height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--btn-color);
  font-size: 13px;
  font-weight: 800;
}
.user-chip .coins {
  font-size: 12.5px;
  color: var(--muted);
  border-left: 1px solid var(--line);
  padding-left: 9px;
  font-variant-numeric: tabular-nums;
}

/* ---------- модальные окна ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 7, 12, .66);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  padding: 18px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.modal-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow: hidden;
  box-shadow: 0 30px 70px -24px rgba(0, 0, 0, .75);
}
.modal-scroll {
  padding: 22px 22px 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-footer {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--line);
  background: var(--card);
}
.modal-close {
  position: absolute;
  top: 10px; right: 10px;
  z-index: 2;
  width: 32px; height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--track);
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); }
.modal-card.wide { max-width: 720px; }
.modal-title { margin: 0 0 12px; font-size: 19px; letter-spacing: -.01em; }
.modal-balance {
  font-size: 30px; font-weight: 800; text-align: center;
  color: var(--btn-color); margin: 6px 0 16px;
}
.modal-balance.small { font-size: 16px; margin: 4px 0 12px; }
.modal-text { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0 0 16px; }
.modal-list { display: flex; flex-direction: column; gap: 9px; }
.modal-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.modal-btn {
  font: inherit; font-size: 14px; font-weight: 700; text-align: center;
  text-decoration: none; padding: 13px 16px; border-radius: 13px; border: 0;
  background: var(--btn-color); color: var(--btn-ink); cursor: pointer;
  transition: filter .15s ease, transform .15s ease;
}
.modal-btn:hover:not(:disabled) { filter: brightness(1.07); }
.modal-btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.modal-btn:disabled { opacity: .4; cursor: not-allowed; }
.modal-hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; text-align: left; }
.modal-hint.err { color: #ff6b81; }
.modal-ok {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 16px; border-radius: 13px;
  background: rgba(64, 200, 120, .14);
  color: #51d18a; font-size: 14.5px; font-weight: 800;
}
.modal-contact {
  background: var(--accent-soft);
  border-radius: 13px;
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.5;
  margin: 0 0 14px;
}
.modal-sep { height: 1px; background: var(--line); margin: 16px 0 14px; }
.modal-label {
  display: block;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 7px;
}
.modal-textarea {
  width: 100%;
  font: inherit;
  font-size: 14.5px;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 13px;
  margin-bottom: 10px;
  outline: none;
  resize: vertical;
  min-height: 74px;
}
.modal-textarea:focus { border-color: var(--btn-color); box-shadow: 0 0 0 3px var(--accent-soft); }
.file-btn { display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
/* выбор количества голосов за монеты */
.qty-row { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 4px 0 10px; }
.qty-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: transparent; color: var(--ink); font-size: 20px; line-height: 1; cursor: pointer;
}
.qty-btn:hover { border-color: var(--btn-color); }
.qty-row input {
  width: 72px; height: 40px; text-align: center; font: inherit; font-size: 17px; font-weight: 800;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  outline: none; -moz-appearance: textfield;
}
.qty-row input::-webkit-outer-spin-button,
.qty-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-row input:focus { border-color: var(--btn-color); box-shadow: 0 0 0 3px var(--accent-soft); }
.qty-all {
  height: 40px; padding: 0 12px; border-radius: 12px; border: 1px dashed var(--line);
  background: transparent; color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 700;
  cursor: pointer;
}
.qty-all:hover { color: var(--btn-color); border-color: var(--btn-color); }

.preview-grid { display: flex; gap: 8px; flex-wrap: wrap; margin: 2px 0 8px; }
.preview-grid img { width: 58px; height: 58px; object-fit: cover; border-radius: 10px;
  border: 1px solid var(--line); }
.preview-grid .file-chip { font-size: 11.5px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 9px; }

.user-chip .user-link {
  display: inline-flex; align-items: center; gap: 9px;
  text-decoration: none; color: inherit;
}
.user-chip .coins {
  font: inherit; font-size: 12.5px; font-weight: 700;
  color: var(--btn-color); background: var(--accent-soft);
  border: 0; border-radius: 999px; padding: 5px 10px; cursor: pointer;
}
.user-chip .coins:hover { filter: brightness(1.1); }

/* ---------- блоки-опросы ---------- */
.poll { padding: 22px 0 6px; }
.poll + .poll {
  margin-top: 26px;
  padding-top: 38px;
  border-top: 1px solid var(--line);
}
.poll-head { text-align: center; margin-bottom: 20px; }
.poll-num {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--muted);
}
.poll-title {
  font-size: clamp(20px, 3.6vw, 29px);
  line-height: 1.2;
  letter-spacing: -.025em;
  margin: 7px 0 6px;
  font-weight: 800;
}
.poll-sub {
  color: var(--muted);
  font-size: clamp(12.5px, 2.2vw, 14px);
  line-height: 1.45;
  margin: 0 auto 14px;
  max-width: 50ch;
}
.poll-head .meta { margin-bottom: 0; }

.chip.ok { border-color: var(--btn-color); color: var(--btn-color); }
.chip.closed { border-color: #ffc247; color: #ffc247; }

/* ---------- сетка карточек ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
/* всегда симметрично: 2 в ряд на телефоне (3 ряда) или 3 в ряд (2 ряда) — без 4+2 */
@media (min-width: 720px) { .grid { grid-template-columns: repeat(3, 1fr); gap: 18px; } }

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 9px 11px;
  box-shadow: var(--shadow);
  transition: transform .18s ease, border-color .18s ease;
}
.card:hover { transform: translateY(-2px); }
.card.solo { grid-column: 1 / -1; }
.card.solo .photo { aspect-ratio: 21 / 9; }
.card.solo .photo .emoji { font-size: 62px; }
.card.mine { border-color: var(--btn-color); }
.card.mine .photo::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 13px;
  box-shadow: inset 0 0 0 2px var(--btn-color);
  pointer-events: none;
}

.photo {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 13px;
  overflow: hidden;
  background: var(--photo-grad);
  display: grid;
  place-items: center;
  margin-bottom: 10px;
}
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .emoji { font-size: 44px; line-height: 1; }
.photo .rank {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #fff;
  background: rgba(0, 0, 0, .5);
  border-radius: 999px;
  padding: 4px 9px;
  backdrop-filter: blur(4px);
}
.photo .mine-flag {
  position: absolute;
  bottom: 8px; left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 2;
  font-size: 11px;
  font-weight: 800;
  color: #fff;
  background: var(--btn-color);
  border-radius: 999px;
  padding: 4px 9px;
}

.card h3 {
  text-align: center;
  font-size: 15.5px;
  line-height: 1.25;
  margin: 0 3px 3px;
  font-weight: 700;
  letter-spacing: -.01em;
  overflow-wrap: anywhere;
}
.votes {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 3px 10px;
  font-variant-numeric: tabular-nums;
}

.vote-btn {
  width: 100%;
  margin-top: auto;
  border: 0;
  border-radius: 11px;
  padding: 11px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--btn-ink);
  background: var(--btn-color);
  cursor: pointer;
  transition: transform .15s ease, filter .2s ease, background .2s ease, color .2s ease;
}
.vote-btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.vote-btn:active:not(:disabled) { transform: translateY(0) scale(.99); }
.vote-btn:focus-visible { outline: 3px solid var(--btn-color); outline-offset: 2px; }
.vote-btn:disabled {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--btn-ink-off);
  cursor: not-allowed;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}
.vote-btn.mine {
  background: transparent;
  border: 1px solid var(--btn-color);
  color: var(--btn-color);
  cursor: default;
  text-transform: none;
  letter-spacing: 0;
}

/* ---------- сообщения ---------- */
.notice {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 15px;
  font-size: 13.5px;
  margin: 0 0 18px;
}
.notice.ok { border-color: var(--btn-color); color: var(--btn-color); }
.notice.warn { border-color: #ffc247; color: #ffc247; }
.notice.hidden { display: none; }

footer {
  margin-top: 34px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
}
footer a { color: var(--muted); }

/* кнопки админки */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 14px 20px;
  font: inherit;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--btn-ink);
  background: var(--btn-color);
  cursor: pointer;
  transition: transform .15s ease, filter .2s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.06); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 560px) {
  .wrap { padding: 24px 14px 44px; }
  .grid { gap: 11px; }
  .card { padding: 7px 7px 9px; border-radius: 15px; }
  .photo { border-radius: 11px; margin-bottom: 8px; }
  .photo .emoji { font-size: 34px; }
  .photo .rank { font-size: 10px; padding: 3px 7px; }
  .card h3 { font-size: 13.5px; margin: 0 2px 2px; }
  .votes { font-size: 11.5px; margin: 0 2px 8px; }
  .vote-btn { font-size: 11.5px; padding: 10px 8px; border-radius: 9px; }
}
