:root {
  --tg-bg: #f4f5f7;
  --tg-text: #151719;
  --tg-hint: #687079;
  --tg-button: #2678e8;
  --tg-button-text: #ffffff;
  --tg-secondary-bg: #ffffff;
  --border: rgba(20, 24, 28, 0.12);
  --yes: #16865b;
  --no: #b94848;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--tg-text);
  background: var(--tg-bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--tg-bg); color: var(--tg-text); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.mini-app { display: grid; place-items: center; padding: max(20px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom)); }
.app-shell { width: 100%; max-width: 480px; }
.poll-card, .login-card, .admin-card, .stat-card {
  background: var(--tg-secondary-bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 12px 40px rgba(19, 30, 43, 0.07);
}
.poll-card { padding: 28px 22px 24px; }
.eyebrow, .section-label { color: var(--tg-hint); font-size: 12px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.poll-card h1 { margin: 10px 0 10px; font-size: clamp(27px, 8vw, 38px); line-height: 1.08; letter-spacing: -.035em; }
.intro { margin-bottom: 26px; color: var(--tg-hint); line-height: 1.5; }
.vote-actions { display: grid; gap: 12px; }
.vote-button, .primary-button, .secondary-button {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 720;
  transition: transform .12s ease, opacity .12s ease, box-shadow .12s ease;
}
.vote-button { min-height: 62px; padding: 14px 18px; color: #fff; font-size: 18px; }
.vote-button.yes { background: var(--yes); }
.vote-button.no { background: var(--no); }
.vote-button.selected { box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .82), 0 0 0 3px rgba(38, 120, 232, .28); }
.vote-button:active, .primary-button:active { transform: translateY(1px); }
.vote-button:disabled { cursor: not-allowed; opacity: .48; }
.status { min-height: 21px; margin: 15px 0 3px; color: var(--tg-hint); font-size: 14px; text-align: center; }
.secondary-button { width: 100%; margin-top: 8px; padding: 12px; background: transparent; color: var(--tg-button); }
.results { margin-top: 16px; padding-top: 18px; border-top: 1px solid var(--border); }
.result-row { display: flex; justify-content: space-between; align-items: baseline; }
.result-row strong { font-size: 20px; }
.result-row-bottom { margin-top: 11px; }
.result-track { height: 10px; margin-top: 9px; overflow: hidden; border-radius: 99px; background: rgba(185, 72, 72, .25); background: color-mix(in srgb, var(--no) 32%, transparent); }
.result-fill { height: 100%; width: 0; border-radius: inherit; background: var(--yes); transition: width .3s ease; }
.total { margin: 20px 0 0; color: var(--tg-hint); font-size: 14px; }
.preview-note { margin: 14px 8px 0; color: var(--tg-hint); font-size: 13px; line-height: 1.45; text-align: center; }

.vote-effect-layer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
}

.confetti-particle {
  --x-mid: 0;
  --y-mid: -40vh;
  --x-end: 0;
  --y-end: 45vh;
  --spin: 540deg;
  --delay: 0ms;
  --duration: 2400ms;
  position: absolute;
  left: 50%;
  top: 56%;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-burst var(--duration) cubic-bezier(.16, .7, .22, 1) var(--delay) forwards;
  will-change: transform, opacity;
}

.confetti-particle.round { border-radius: 50%; }

.vote-sticker {
  width: var(--size);
  height: var(--size);
  object-fit: contain;
  user-select: none;
  filter: drop-shadow(0 7px 8px rgba(0, 0, 0, .2));
  will-change: transform, opacity;
}

.sticker-burst {
  position: absolute;
  left: calc(50% - var(--size) / 2);
  top: calc(54% - var(--size) / 2);
  opacity: 0;
  animation: sticker-burst var(--duration) cubic-bezier(.15, .72, .24, 1) var(--delay) forwards;
}

.sticker-rain {
  position: absolute;
  top: calc(-1 * var(--size) - 20px);
  opacity: 0;
  animation: sticker-rain var(--duration) cubic-bezier(.28, .5, .55, .95) var(--delay) forwards;
}

@keyframes confetti-burst {
  0% { opacity: 0; transform: translate(0, 0) rotate(0) scale(.5); }
  8% { opacity: 1; }
  52% { opacity: 1; transform: translate(var(--x-mid), var(--y-mid)) rotate(calc(var(--spin) * .62)) scale(1); }
  100% { opacity: 0; transform: translate(var(--x-end), var(--y-end)) rotate(var(--spin)) scale(.8); }
}

@keyframes sticker-burst {
  0% { opacity: 0; transform: translate(0, 0) rotate(0) scale(.2); }
  10% { opacity: 1; }
  55% { opacity: 1; transform: translate(var(--x-mid), var(--y-mid)) rotate(calc(var(--spin) * .55)) scale(1); }
  100% { opacity: 0; transform: translate(var(--x-end), var(--y-end)) rotate(var(--spin)) scale(.88); }
}

@keyframes sticker-rain {
  0% { opacity: 0; transform: translate(0, 0) rotate(0) scale(.8); }
  8% { opacity: 1; }
  88% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--drift), calc(100vh + var(--size) + 40px)) rotate(var(--spin)) scale(1.08); }
}

.admin-body { background: #f3f5f7; color: #17202a; }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(100%, 390px); padding: 30px; }
.login-card h1 { margin: 8px 0 24px; font-size: 32px; }
.login-card label { display: block; margin-bottom: 8px; font-weight: 650; }
.login-card input { width: 100%; padding: 13px 14px; border: 1px solid #cbd1d8; border-radius: 10px; background: #fff; color: #17202a; }
.primary-button { padding: 12px 17px; background: #1f6fd1; color: #fff; }
.login-card .primary-button { width: 100%; margin-top: 18px; }
.form-error { margin: 10px 0 -6px; color: #aa3434; font-size: 14px; }
.admin-header { display: flex; justify-content: space-between; align-items: center; max-width: 1180px; margin: 0 auto; padding: 30px 24px 12px; }
.admin-header h1 { margin: 4px 0 0; font-size: 28px; }
.text-button { border: 0; background: transparent; color: #4b5866; cursor: pointer; }
.admin-main { max-width: 1180px; margin: 0 auto; padding: 18px 24px 60px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat-card { position: relative; padding: 20px; border-radius: 16px; }
.stat-card span { display: block; color: #687582; font-size: 14px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 32px; }
.stat-card small { position: absolute; right: 20px; bottom: 23px; color: #687582; }
.admin-card { margin-top: 16px; padding: 22px; border-radius: 16px; }
.randomizer-card, .table-heading { display: flex; justify-content: space-between; gap: 24px; align-items: center; }
.randomizer-result { min-width: 260px; }
.randomizer-result h2, .table-heading h2 { margin: 5px 0 5px; font-size: 21px; }
.randomizer-result p { margin: 0; color: #687582; }
.randomizer-result .winner-meta { margin-top: 7px; font-size: 13px; }
.randomizer-form { display: grid; grid-template-columns: minmax(190px, 1fr) auto; align-items: end; gap: 12px 16px; }
.randomizer-form label:not(.checkbox-label), .participant-controls label { display: grid; gap: 6px; color: #687582; font-size: 12px; font-weight: 650; }
.randomizer-form select, .participant-controls select, .participant-controls input {
  min-height: 40px;
  padding: 8px 11px;
  border: 1px solid #cbd3dc;
  border-radius: 9px;
  background: #fff;
  color: #17202a;
}
.checkbox-label { display: flex; align-items: center; gap: 8px; color: #53606d; font-size: 14px; }
.checkbox-label input { width: 17px; height: 17px; margin: 0; accent-color: #1f6fd1; }
.participant-controls { display: grid; grid-template-columns: minmax(190px, 1fr) 160px 210px auto auto; align-items: end; gap: 10px; margin-top: 18px; padding: 14px; border-radius: 12px; background: #f4f6f8; }
.participant-controls label span { display: block; }
.search-field input { width: 100%; }
.reset-link { align-self: center; padding: 10px 7px; color: #53606d; font-size: 14px; text-decoration: none; }
.telegram-link { color: #1769c2; font-weight: 650; text-decoration: none; }
.telegram-link:hover { text-decoration: underline; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters a { padding: 8px 11px; border-radius: 9px; color: #53606d; text-decoration: none; font-size: 14px; }
.filters a.active { background: #e8eff8; color: #145cae; }
.table-wrap { margin-top: 18px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 13px 12px; border-top: 1px solid #e4e8ec; text-align: left; font-size: 14px; }
th { color: #6a7681; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.vote-row td { transition: background-color .12s ease; }
.vote-row-yes td { background: rgba(29, 153, 102, .09); }
.vote-row-no td { background: rgba(201, 65, 65, .10); }
.vote-row-yes:hover td { background: rgba(29, 153, 102, .16); }
.vote-row-no:hover td { background: rgba(201, 65, 65, .17); }
.choice-badge { display: inline-block; padding: 5px 8px; border-radius: 7px; font-size: 12px; font-weight: 700; }
.choice-badge.yes { background: #e2f5ed; color: #096b46; }
.choice-badge.no { background: #fae8e8; color: #963737; }
.empty-state { padding: 35px; color: #74808c; text-align: center; }
.notice { margin-bottom: 14px; padding: 12px 15px; border-radius: 10px; background: #e8eef5; }
.notice.success { background: #e1f4eb; color: #116a48; }
.notice.warning { background: #fff0d9; color: #81571b; }

@media (max-width: 700px) {
  .stats-grid { grid-template-columns: 1fr; }
  .randomizer-card, .table-heading { align-items: stretch; flex-direction: column; }
  .randomizer-form, .participant-controls { grid-template-columns: 1fr; }
  .randomizer-form .primary-button, .participant-controls .primary-button { width: 100%; }
  .admin-header, .admin-main { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .confetti-particle, .vote-sticker { animation-duration: 1ms !important; animation-delay: 0ms !important; }
}
