:root {
  --purple: #7C3AED;
  --purple-deep: #5B21B6;
  --purple-soft: #EDE9FE;
  --purple-border: #C4B5FD;
  --ink: #1E1B2E;
  --muted: #6B6680;
  --bg: #FBFAFF;
  --card: #FFFFFF;
  --milk: #F5F3FA;
  --gold: #F59E0B;
  --danger: #E11D48;
  --radius: 22px;
  --shadow: 0 10px 40px rgba(109, 40, 217, .10);
  --shadow-lg: 0 24px 70px rgba(109, 40, 217, .22);
}

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

html, body { height: 100%; }

body {
  font-family: 'Manrope', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}

.ic { width: 1.15em; height: 1.15em; flex: none; }

/* ---------- Фоновые волны ---------- */
.bg-decor { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.wave { position: absolute; width: 42vw; max-width: 640px; }
.wave-tl { top: -40px; left: -60px; transform: rotate(8deg); }
.wave-br { bottom: -30px; right: -60px; transform: rotate(188deg); }

/* ---------- Шапка ---------- */
.site-header {
  position: relative; z-index: 2;
  max-width: 1780px; margin: 0 auto;
  padding: 26px 44px 6px;
}
.brand { display: flex; align-items: center; gap: 22px; }
.brand-logo img { height: 56px; width: auto; display: block; }
.brand-text h1 {
  font-family: 'Unbounded', 'Manrope', sans-serif;
  font-size: clamp(22px, 2.2vw, 34px);
  font-weight: 700; letter-spacing: -.5px; line-height: 1.15;
}
.brand-text .accent { color: var(--purple); }
.spark { color: var(--purple); font-size: .7em; vertical-align: super; }
.brand-text p { color: var(--muted); font-size: clamp(13px, 1.05vw, 17px); margin-top: 4px; font-weight: 500; }

/* ---------- Выбор мероприятия ---------- */
.event-bar { position: relative; z-index: 30; display: flex; justify-content: center; padding: 18px 20px 26px; }
.event-select { position: relative; width: min(560px, 92vw); }
.event-pill {
  width: 100%; display: flex; align-items: center; gap: 18px;
  background: #fff; border: 1.5px solid var(--purple-border);
  border-radius: 999px; padding: 14px 28px; cursor: pointer;
  color: var(--purple-deep); box-shadow: var(--shadow);
  transition: box-shadow .25s, border-color .25s;
  font-family: inherit;
}
.event-pill:hover { box-shadow: var(--shadow-lg); border-color: var(--purple); }
.event-pill .ic { width: 34px; height: 34px; }
.event-pill-text { flex: 1; text-align: left; line-height: 1.15; }
.event-pill-text small { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.event-pill-text strong { font-size: clamp(18px, 1.6vw, 24px); font-weight: 800; color: var(--ink); }
.chevron { transition: transform .25s; width: 26px; height: 26px; }
.event-select.open .chevron { transform: rotate(180deg); }

.event-dropdown {
  position: absolute; top: calc(100% + 10px); left: 0; right: 0;
  background: #fff; border: 1.5px solid var(--purple-border);
  border-radius: 24px; box-shadow: var(--shadow-lg);
  padding: 12px; z-index: 50;
  opacity: 0; visibility: hidden; transform: translateY(-8px);
  transition: opacity .2s, transform .2s, visibility .2s;
}
.event-select.open .event-dropdown { opacity: 1; visibility: visible; transform: translateY(0); }
.event-dropdown ul { list-style: none; max-height: 260px; overflow-y: auto; }
.event-item {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-radius: 14px; cursor: pointer;
  font-weight: 700; font-size: 17px; transition: background .15s;
}
.event-item:hover { background: var(--purple-soft); }
.event-item.active { background: var(--purple-soft); color: var(--purple-deep); }
.event-item .ev-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-item .ev-meta { font-size: 12px; color: var(--muted); font-weight: 600; }
.ev-action {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 15px; padding: 4px 7px; border-radius: 8px; line-height: 1;
}
.ev-action:hover { background: #fff; color: var(--purple); }
.ev-action.danger:hover { color: var(--danger); }
.add-event-btn {
  width: 100%; margin-top: 10px; border: none; cursor: pointer;
  background: linear-gradient(135deg, #8B5CF6, #6D28D9); color: #fff;
  border-radius: 14px; padding: 14px; font-family: inherit;
  font-size: 16px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px;
}
.plus-circle {
  width: 24px; height: 24px; border-radius: 50%; background: rgba(255,255,255,.22);
  display: inline-flex; align-items: center; justify-content: center;
}

/* ---------- Сетка ---------- */
.layout {
  position: relative; z-index: 2;
  max-width: 1780px; margin: 0 auto;
  padding: 0 44px 48px;
  display: grid; grid-template-columns: 360px 1fr 360px; gap: 26px;
  align-items: stretch;
}

/* ---------- Карточки ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  border: 1px solid #EFEAFB; box-shadow: var(--shadow);
  padding: 22px; display: flex; flex-direction: column;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-title {
  display: flex; align-items: center; gap: 10px;
  font-size: 19px; font-weight: 800;
}
.card-title .ic { width: 26px; height: 26px; color: var(--purple); }
.count-badge {
  background: var(--purple-soft); color: var(--purple-deep);
  font-weight: 800; font-size: 15px; border-radius: 999px; padding: 4px 16px;
}
.count-badge.gold { background: #FEF3C7; color: #B45309; }

/* ---------- Участники ---------- */
.list-wrap {
  position: relative; flex: 1; min-height: 220px; margin-bottom: 14px;
  background: var(--milk); border-radius: 16px; border: 1px solid #EDE9F8;
  overflow: hidden;
}
.participant-list { list-style: none; height: 100%; max-height: 340px; overflow-y: auto; padding: 10px 8px 10px 14px; }
.participant-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 10px; border-radius: 10px; font-size: 16px; font-weight: 600;
}
.participant-list li:hover { background: #fff; }
.participant-list .num { color: var(--muted); font-size: 13px; width: 24px; flex: none; font-variant-numeric: tabular-nums; }
.participant-list .pname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.participant-list .p-del {
  border: none; background: none; cursor: pointer; color: #C9C3DA;
  font-size: 17px; line-height: 1; padding: 2px 7px; border-radius: 7px; visibility: hidden;
}
.participant-list li:hover .p-del { visibility: visible; }
.participant-list .p-del:hover { color: var(--danger); background: #FFF1F2; }
.empty-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; color: #B6AFCB; font-size: 14px; font-weight: 600; padding: 20px;
  pointer-events: none;
}
.participants-card .empty-hint { position: absolute; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  border-radius: 999px; cursor: pointer; font-family: inherit; font-weight: 700;
  transition: transform .15s, box-shadow .2s, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn-outline {
  background: #fff; border: 1.5px solid var(--purple); color: var(--purple-deep);
  font-size: 15px; padding: 12px 20px;
}
.btn-outline:hover { background: var(--purple-soft); }
.btn-upload { width: 100%; margin-bottom: 12px; }

.manual-add { display: flex; gap: 10px; margin-bottom: 10px; }
.manual-add input {
  flex: 1; border: 1.5px solid #E5E0F2; border-radius: 999px; padding: 11px 18px;
  font-family: inherit; font-size: 15px; font-weight: 600; color: var(--ink); outline: none;
  transition: border-color .2s, box-shadow .2s; background: #fff;
}
.manual-add input:focus { border-color: var(--purple); box-shadow: 0 0 0 4px rgba(124,58,237,.12); }
.btn-icon {
  width: 46px; height: 46px; flex: none;
  background: linear-gradient(135deg, #8B5CF6, #6D28D9); color: #fff; border: none;
}
.btn-icon:hover { box-shadow: var(--shadow-lg); }
.link-btn {
  border: none; background: none; cursor: pointer; font-family: inherit;
  color: var(--muted); font-size: 13.5px; font-weight: 700; padding: 4px;
  align-self: center; text-decoration: underline; text-underline-offset: 3px;
}
.link-btn.danger:hover { color: var(--danger); }
.import-msg { min-height: 20px; text-align: center; font-size: 13.5px; font-weight: 700; margin-top: 6px; }
.import-msg.ok { color: #059669; }
.import-msg.err { color: var(--danger); }

/* ---------- Рандомайзер ---------- */
.randomizer {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 10px 0 20px;
}
.drum-wrap { position: relative; width: min(460px, 100%); }
.drum-glow {
  position: absolute; inset: -12% -18%;
  background: radial-gradient(ellipse at center, rgba(139,92,246,.30), transparent 65%);
  filter: blur(10px); transition: opacity .4s;
}
.drum {
  position: relative; aspect-ratio: 1.12 / 1;
  background: linear-gradient(165deg, rgba(167,139,250,.65), rgba(109,40,217,.85));
  clip-path: polygon(11% 3%, 89% 3%, 97.5% 97%, 2.5% 97%);
}
.drum-inner {
  position: absolute; inset: 4px;
  clip-path: polygon(11% 3%, 89% 3%, 97.5% 97%, 2.5% 97%);
  background: linear-gradient(180deg, rgba(245,242,255,.95) 0%, rgba(233,226,252,.85) 55%, rgba(214,202,247,.8) 100%);
  overflow: hidden;
}
.drum-inner::before {
  content: ''; position: absolute; top: 0; bottom: 0; left: 8%; width: 12%;
  background: linear-gradient(180deg, rgba(255,255,255,.75), rgba(255,255,255,0));
  transform: skewX(-4deg); pointer-events: none;
}
.drum-inner::after {
  content: ''; position: absolute; top: 0; bottom: 0; right: 6%; width: 7%;
  background: linear-gradient(180deg, rgba(255,255,255,.5), rgba(255,255,255,0));
  transform: skewX(-4deg); pointer-events: none;
}
.drum-rim {
  position: absolute; top: 3.2%; left: 15%; right: 15%; height: 30px;
  border: 3px solid rgba(255,255,255,.9); border-radius: 50%;
  box-shadow: 0 3px 10px rgba(109,40,217,.18), inset 0 2px 6px rgba(109,40,217,.12);
}
.drum-base {
  height: 34px; margin: -6px 4% 0;
  background: linear-gradient(180deg, #E9E2FB, #C9B8F2);
  border-radius: 12px 12px 26px 26px;
  box-shadow: 0 14px 30px rgba(109,40,217,.25);
}
.envelope {
  position: absolute; width: 82px; height: 58px;
  background: linear-gradient(150deg, #FFFFFF, #F1EDFE);
  border-radius: 9px;
  box-shadow: 0 12px 24px rgba(91,33,182,.18), inset 0 0 0 1px rgba(255,255,255,.9);
  display: flex; align-items: center; justify-content: center;
  animation: floaty 5.5s ease-in-out infinite;
  will-change: transform;
}
.envelope::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 48%;
  border-radius: 9px 9px 0 0;
  background: linear-gradient(180deg, rgba(139,92,246,.07), rgba(139,92,246,0));
  border-bottom: 1.5px solid #E7E0F9;
}
.float-logo {
  position: absolute; left: 40%; top: 12%;
  width: 108px; height: 108px; border-radius: 50%;
  background: linear-gradient(150deg, #FFFFFF, #F1EDFE);
  box-shadow: 0 16px 34px rgba(91,33,182,.22), inset 0 0 0 1px rgba(255,255,255,.9);
  display: flex; align-items: center; justify-content: center;
  animation: floaty 6s ease-in-out infinite;
  will-change: transform;
}
.sko-dot { position: relative; width: 55%; aspect-ratio: 1.9 / 1; }
.sko-dot::before, .sko-dot::after {
  content: ''; position: absolute; left: 0; width: 100%; height: 44%;
  background: linear-gradient(135deg, #8B5CF6, #6D28D9);
}
.sko-dot::before { top: 0; border-radius: 999px 999px 0 0; }
.sko-dot::after { bottom: 0; border-radius: 0 0 999px 999px; }
.float-logo .sko-dot { width: 58%; }
@keyframes floaty {
  0%, 100% { transform: translateY(0) rotate(var(--rot, 0deg)); }
  50% { transform: translateY(-13px) rotate(calc(var(--rot, 0deg) + 3deg)); }
}
.drum.active .drum-glow { animation: pulseGlow 1s ease-in-out infinite; }
.drum.active .envelope, .drum.active .float-logo { animation: jitter .16s linear infinite; }
@keyframes pulseGlow { 0%,100% { opacity: .8; } 50% { opacity: 1; transform: scale(1.04); } }
@keyframes jitter {
  0% { transform: translate(0, 0) rotate(var(--rot, 0deg)); }
  25% { transform: translate(-7px, 5px) rotate(calc(var(--rot, 0deg) - 9deg)); }
  50% { transform: translate(6px, -6px) rotate(calc(var(--rot, 0deg) + 8deg)); }
  75% { transform: translate(-5px, -4px) rotate(calc(var(--rot, 0deg) + 4deg)); }
  100% { transform: translate(5px, 6px) rotate(var(--rot, 0deg)); }
}

.scramble {
  font-family: 'Unbounded', 'Manrope', sans-serif;
  font-size: clamp(20px, 2vw, 30px); font-weight: 700;
  min-height: 1.4em; text-align: center; color: var(--purple-deep);
  max-width: 640px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: transform .1s;
}
.btn-draw {
  border: none; font-size: clamp(18px, 1.5vw, 24px);
  padding: 20px 58px; color: #fff;
  background: linear-gradient(135deg, #8B5CF6, #6D28D9);
  box-shadow: 0 16px 40px rgba(109,40,217,.35);
}
.btn-draw:hover:not(:disabled) { box-shadow: 0 20px 54px rgba(109,40,217,.5); transform: translateY(-2px); }
.btn-draw:disabled { opacity: .65; cursor: wait; }
.btn-draw .ic { width: 26px; height: 26px; }

/* ---------- Правая колонка ---------- */
.right-col { display: flex; flex-direction: column; gap: 26px; }
.prize-img-wrap {
  border-radius: 16px; overflow: hidden; border: 1px solid #EDE9F8;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.6);
}
.prize-img-wrap img { width: 100%; display: block; }
.prize-caption { margin-top: 12px; font-size: 13.5px; color: var(--muted); font-weight: 600; line-height: 1.5; }
.history-list { list-style: none; overflow-y: auto; max-height: 200px; display: flex; flex-direction: column; gap: 6px; }
.history-list li {
  display: flex; align-items: center; gap: 10px;
  background: var(--milk); border-radius: 12px; padding: 9px 14px; font-size: 14.5px; font-weight: 700;
}
.history-list .h-prize {
  flex: none; font-size: 11.5px; font-weight: 800; color: #B45309;
  background: #FEF3C7; border-radius: 999px; padding: 3px 10px;
}
.history-list .h-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-list .h-time { flex: none; font-size: 12px; color: var(--muted); font-weight: 600; }
.history-card .empty-hint { position: static; padding: 14px 0 4px; }

/* ---------- Экран победителя ---------- */
.winner-overlay {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(76,29,149,.92), rgba(30,10,60,.97));
  opacity: 0; visibility: hidden; transition: opacity .45s, visibility .45s;
}
.winner-overlay.show { opacity: 1; visibility: visible; }
#confettiCanvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.winner-content {
  position: relative; text-align: center; color: #fff;
  transform: scale(.7); opacity: 0; transition: transform .5s cubic-bezier(.2,1.4,.4,1), opacity .4s;
}
.winner-overlay.show .winner-content { transform: scale(1); opacity: 1; }
.trophy { font-size: clamp(56px, 7vw, 96px); animation: trophyBounce 1.6s ease-in-out infinite; filter: drop-shadow(0 10px 24px rgba(245,158,11,.5)); }
@keyframes trophyBounce { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-14px) rotate(4deg); } }
.winner-heading {
  font-family: 'Unbounded', sans-serif; font-size: clamp(34px, 4.6vw, 64px);
  font-weight: 900; margin: 10px 0 26px; letter-spacing: 1px;
  text-shadow: 0 6px 30px rgba(167,139,250,.6);
}
.winner-pill {
  display: inline-flex; align-items: center; gap: 16px;
  background: linear-gradient(135deg, #8B5CF6, #6D28D9);
  border: 2px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: 20px 52px;
  font-family: 'Unbounded', sans-serif; font-weight: 700;
  font-size: clamp(24px, 3vw, 44px);
  box-shadow: 0 20px 60px rgba(0,0,0,.35), 0 0 60px rgba(139,92,246,.55);
}
.winner-pill .ic { width: .9em; height: .9em; opacity: .9; }
.winner-sub { margin-top: 20px; font-size: clamp(15px, 1.3vw, 20px); font-weight: 600; color: #D8CCF5; }
.btn-light {
  margin-top: 34px; border: none; font-size: 17px; font-weight: 800;
  padding: 14px 38px; border-radius: 999px; cursor: pointer;
  background: #fff; color: var(--purple-deep); font-family: inherit;
  box-shadow: 0 12px 34px rgba(0,0,0,.3);
}
.btn-light:hover { transform: translateY(-2px); }

/* ---------- Модальное окно ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(30,27,46,.45); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity .25s, visibility .25s;
}
.modal-backdrop.show { opacity: 1; visibility: visible; }
.modal {
  background: #fff; border-radius: 24px; padding: 30px 32px;
  width: min(480px, 92vw); box-shadow: var(--shadow-lg);
  transform: translateY(14px); transition: transform .25s;
}
.modal-backdrop.show .modal { transform: translateY(0); }
.modal h3 { font-size: 21px; font-weight: 800; margin-bottom: 10px; }
.modal p { color: var(--muted); font-size: 15px; font-weight: 600; line-height: 1.55; }
.modal-input {
  display: none; width: 100%; margin-top: 16px;
  border: 1.5px solid #E5E0F2; border-radius: 14px; padding: 13px 18px;
  font-family: inherit; font-size: 16px; font-weight: 600; outline: none;
}
.modal-input.visible { display: block; }
.modal-input:focus { border-color: var(--purple); box-shadow: 0 0 0 4px rgba(124,58,237,.12); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; }
.modal-actions .btn { font-size: 15px; padding: 12px 26px; }

/* ---------- Скроллбар ---------- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C9BEE8; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--purple-border); }

/* ---------- Адаптив ---------- */
@media (max-width: 1280px) {
  .layout { grid-template-columns: 320px 1fr 320px; padding: 0 24px 36px; }
  .site-header { padding: 22px 24px 4px; }
}
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .randomizer { grid-column: 1 / -1; order: -1; }
  .right-col { grid-column: 1 / -1; flex-direction: row; }
  .right-col .card { flex: 1; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .right-col { flex-direction: column; }
  .brand { flex-direction: column; align-items: flex-start; gap: 12px; }
}
