:root {
  --bg: #120024;
  --bg2: #1a0033;
  --pink: #ff3cac;
  --purple: #7d3cff;
  --cyan: #00e0ff;
  --yellow: #ffd93c;
  --green: #4cff8f;
  --ink: #fff;
  --soft: rgba(255, 255, 255, 0.62);
  --glass: rgba(255, 255, 255, 0.08);
  --glass-brd: rgba(255, 255, 255, 0.16);
  --radius: 22px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Onest', system-ui, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; }

/* ---------- Фон ---------- */
#bg-fx { position: fixed; inset: 0; z-index: 0; overflow: hidden; background: radial-gradient(120% 120% at 50% 0%, var(--bg2), var(--bg) 70%); }
.blob { position: absolute; border-radius: 50%; filter: blur(70px); opacity: 0.55; mix-blend-mode: screen; animation: float 14s ease-in-out infinite; }
.b1 { width: 60vw; height: 60vw; background: var(--pink); top: -10%; left: -20%; }
.b2 { width: 55vw; height: 55vw; background: var(--purple); bottom: -15%; right: -15%; animation-delay: -4s; }
.b3 { width: 45vw; height: 45vw; background: var(--cyan); top: 40%; left: 30%; animation-delay: -8s; }
@keyframes float { 0%,100% { transform: translate(0,0) scale(1); } 33% { transform: translate(6%,-8%) scale(1.15); } 66% { transform: translate(-6%,6%) scale(0.9); } }
.grain { position: absolute; inset: 0; opacity: 0.05; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence baseFrequency='0.9'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"); }

/* ---------- Каркас ---------- */
#app { position: relative; z-index: 1; height: 100%; width: 100%; max-width: 520px; margin: 0 auto; }

.screen {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  padding: max(24px, env(safe-area-inset-top)) 22px max(24px, env(safe-area-inset-bottom));
  overflow-y: auto;
}
.screen.active { display: flex; }

/* ---------- Типографика/утилиты ---------- */
h2 { font-family: 'Unbounded', sans-serif; font-weight: 800; font-size: 1.6rem; line-height: 1.15; }
.soft { color: var(--soft); }
.center { text-align: center; }
.hint { color: var(--soft); font-size: 0.85rem; text-align: center; margin-top: 14px; }

/* ---------- Кнопки ---------- */
.btn {
  font-family: 'Unbounded', sans-serif; font-weight: 700;
  border: none; border-radius: 16px; cursor: pointer;
  padding: 16px 22px; font-size: 1rem; color: var(--ink);
  transition: transform 0.12s ease, filter 0.2s ease;
  position: relative; overflow: hidden;
}
.btn:active { transform: scale(0.95); }
.btn-primary {
  background: linear-gradient(120deg, var(--pink), var(--purple));
  box-shadow: 0 10px 30px rgba(125, 60, 255, 0.5), inset 0 1px 0 rgba(255,255,255,0.3);
}
.btn-primary:active { filter: brightness(1.1); }
.btn-ghost { background: var(--glass); border: 1.5px solid var(--glass-brd); backdrop-filter: blur(10px); }
.btn-text { background: none; color: var(--soft); font-weight: 500; padding: 10px; }
.btn-tiny { background: var(--glass); border: 1px solid var(--glass-brd); padding: 8px 14px; font-size: 0.8rem; border-radius: 12px; }

/* ---------- Главная ---------- */
.screen[data-screen="home"] { justify-content: center; align-items: center; gap: 40px; }
.logo { text-align: center; }
.logo-word {
  display: block; font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 4.2rem; letter-spacing: -2px;
  background: linear-gradient(120deg, var(--cyan), var(--pink), var(--yellow));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 6px 30px rgba(255,60,172,0.5));
}
.logo-sub { display: block; margin-top: 8px; color: var(--soft); font-size: 0.9rem; letter-spacing: 2px; text-transform: uppercase; }
.home-actions { width: 100%; display: flex; flex-direction: column; gap: 16px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--soft); font-size: 0.8rem; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--glass-brd); }
.join-box { display: flex; gap: 10px; }
.join-box input { flex: 1; }

input, textarea {
  width: 100%; background: var(--glass); border: 1.5px solid var(--glass-brd);
  border-radius: 16px; padding: 16px 18px; color: var(--ink); font-size: 1.05rem;
  font-family: 'Onest', sans-serif; outline: none; backdrop-filter: blur(10px);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input:focus, textarea:focus { border-color: var(--pink); box-shadow: 0 0 0 4px rgba(255,60,172,0.18); }
input::placeholder, textarea::placeholder { color: rgba(255,255,255,0.35); }
#join-code { text-align: center; letter-spacing: 8px; font-weight: 700; font-family: 'Unbounded', sans-serif; }

/* ---------- Карточка (имя) ---------- */
.screen[data-screen="name"] { justify-content: center; }
.card {
  background: var(--glass); border: 1.5px solid var(--glass-brd); backdrop-filter: blur(16px);
  border-radius: var(--radius); padding: 28px 24px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 16px;
}
.card h2 { text-align: center; }

/* ---------- Лобби ---------- */
.room-head { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 8px; }
.room-code {
  font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 3.2rem; letter-spacing: 10px;
  background: linear-gradient(120deg, var(--cyan), var(--green)); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.lobby-status { text-align: center; font-family: 'Unbounded', sans-serif; font-size: 1.1rem; margin: 20px 0; }
.players-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.player-slot {
  background: var(--glass); border: 1.5px solid var(--glass-brd); border-radius: 18px;
  padding: 20px 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; position: relative;
  min-height: 120px; justify-content: center;
}
.player-slot.empty { border-style: dashed; opacity: 0.6; }
.player-slot.filled { background: linear-gradient(160deg, rgba(255,60,172,0.18), rgba(125,60,255,0.12)); border-color: rgba(255,60,172,0.4); }
.avatar {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font-family: 'Unbounded', sans-serif; font-weight: 800; font-size: 1.4rem;
  background: linear-gradient(140deg, var(--pink), var(--purple)); box-shadow: 0 6px 18px rgba(125,60,255,0.4);
}
.avatar.ghost { background: var(--glass); color: var(--soft); box-shadow: none; }
.pname { font-weight: 600; font-size: 0.95rem; text-align: center; word-break: break-word; }
.crown { position: absolute; top: 8px; right: 10px; color: var(--yellow); }

/* ---------- Верхняя панель + таймер ---------- */
.top-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.round-pill {
  background: var(--glass); border: 1px solid var(--glass-brd); border-radius: 999px;
  padding: 8px 16px; font-family: 'Unbounded', sans-serif; font-weight: 600; font-size: 0.82rem;
}
.timer { position: relative; width: 54px; height: 54px; }
.timer svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.timer circle { fill: none; stroke-width: 3.5; }
.tr-bg { stroke: rgba(255,255,255,0.12); }
.tr-fg { stroke: var(--cyan); stroke-linecap: round; transition: stroke-dashoffset 0.1s linear; }
.timer-num { position: absolute; inset: 0; display: grid; place-items: center; font-family: 'Unbounded', sans-serif; font-weight: 800; font-size: 1.2rem; }
.timer.urgent .tr-fg { stroke: var(--pink); }
.timer.urgent .timer-num { color: var(--pink); }

/* ---------- Написание ---------- */
.prompt-card {
  background: linear-gradient(150deg, rgba(0,224,255,0.14), rgba(125,60,255,0.12));
  border: 1.5px solid var(--glass-brd); border-radius: var(--radius); padding: 28px 22px;
  font-family: 'Unbounded', sans-serif; font-weight: 600; font-size: 1.4rem; line-height: 1.35;
  box-shadow: var(--shadow); margin-bottom: 22px;
}
.write-input-wrap { display: flex; flex-direction: column; gap: 14px; }
#answer-text { font-size: 1.1rem; line-height: 1.4; resize: none; }
.write-done { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: 20px; }
.big-check { width: 90px; height: 90px; border-radius: 50%; display: grid; place-items: center; font-size: 3rem;
  background: linear-gradient(140deg, var(--green), var(--cyan)); box-shadow: 0 12px 40px rgba(76,255,143,0.4); }
.write-done p { font-family: 'Unbounded', sans-serif; font-size: 1.05rem; }
.answered-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.ans-chip { display: flex; align-items: center; gap: 6px; background: var(--glass); border: 1px solid var(--glass-brd); border-radius: 999px; padding: 6px 12px; font-size: 0.82rem; opacity: 0.6; }
.ans-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--soft); }
.ans-chip.done { opacity: 1; border-color: var(--green); }
.ans-chip.done .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }

/* ---------- Слайдер ---------- */
.slider { position: relative; flex: 1; display: flex; margin-bottom: 14px;
  overflow-x: auto; overflow-y: hidden; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; }
.slider::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; min-width: 100%; scroll-snap-align: center; padding: 8px 4px; overflow-y: auto;
  display: flex; flex-direction: column; justify-content: center; gap: 16px; }
.slide-num { font-family: 'Unbounded', sans-serif; font-weight: 700; font-size: 0.85rem; color: var(--cyan); text-transform: uppercase; letter-spacing: 2px; text-align: center; }
.slide-prompt { font-family: 'Unbounded', sans-serif; font-weight: 600; font-size: 1.5rem; line-height: 1.35; text-align: center;
  background: linear-gradient(150deg, rgba(0,224,255,0.14), rgba(125,60,255,0.12)); border: 1.5px solid var(--glass-brd); border-radius: 20px 20px 4px 20px; padding: 24px 20px; }
.slide-answer { font-family: 'Unbounded', sans-serif; font-weight: 700; font-size: 1.6rem; line-height: 1.35; text-align: center;
  background: linear-gradient(150deg, var(--pink), var(--purple)); border-radius: 4px 20px 20px 20px; padding: 24px 20px; box-shadow: var(--shadow); }
.slider-dots { display: flex; gap: 8px; justify-content: center; margin-bottom: 14px; }
.slider-dots .dot { width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.25); transition: all 0.3s ease; }
.slider-dots .dot.active { background: var(--cyan); width: 22px; border-radius: 4px; }
.slider-nav { display: flex; align-items: center; justify-content: center; gap: 20px; }
.slider-nav .btn { width: 56px; height: 56px; padding: 0; font-size: 1.6rem; border-radius: 50%; display: grid; place-items: center; }

/* ---------- Голосование ---------- */
.vote-list { display: flex; flex-direction: column; gap: 14px; }
.vote-card {
  text-align: left; background: var(--glass); border: 1.5px solid var(--glass-brd); border-radius: 20px;
  padding: 18px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; width: 100%;
}
.vote-card .vote-prompt { color: var(--soft); font-size: 0.9rem; line-height: 1.3; }
.vote-card .vote-answer { font-family: 'Unbounded', sans-serif; font-weight: 700; font-size: 1.2rem; line-height: 1.3; }
.vote-cta { align-self: flex-start; margin-top: 4px; font-family: 'Unbounded', sans-serif; font-size: 0.8rem; color: var(--pink); border: 1px solid rgba(255,60,172,0.4); border-radius: 999px; padding: 5px 14px; }
.vote-card.mine { opacity: 0.55; cursor: not-allowed; border-style: dashed; }
.mine-tag { font-size: 0.78rem; color: var(--yellow); font-family: 'Unbounded', sans-serif; }
.vote-card.chosen { border-color: var(--green); box-shadow: 0 0 0 3px rgba(76,255,143,0.3); }
.vote-done { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: 30px; }
.vote-done .big-check { background: linear-gradient(140deg, var(--yellow), var(--pink)); }

/* ---------- Итоги ---------- */
.results-title { margin-bottom: 20px; }
.results-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.result-card {
  display: flex; align-items: center; gap: 14px; background: var(--glass); border: 1.5px solid var(--glass-brd);
  border-radius: 18px; padding: 16px; transform: translateY(0);
}
.result-card:first-child { background: linear-gradient(150deg, rgba(255,217,60,0.18), rgba(255,60,172,0.12)); border-color: rgba(255,217,60,0.4); }
.result-rank { font-family: 'Unbounded', sans-serif; font-weight: 800; font-size: 1.3rem; min-width: 34px; text-align: center; }
.result-body { flex: 1; }
.result-answer { font-size: 0.98rem; line-height: 1.35; }
.result-answer b { color: var(--cyan); }
.result-author { font-family: 'Unbounded', sans-serif; font-weight: 700; font-size: 0.95rem; margin-top: 6px; color: var(--pink); }
.result-voters { font-size: 0.78rem; color: var(--soft); margin-top: 4px; }
.result-votes { text-align: center; font-family: 'Unbounded', sans-serif; font-size: 0.72rem; color: var(--soft); }
.result-votes span { display: block; font-size: 1.8rem; font-weight: 900; color: var(--yellow); }

.scoreboard { background: var(--glass); border: 1.5px solid var(--glass-brd); border-radius: 20px; padding: 18px; }
.sb-title { font-family: 'Unbounded', sans-serif; font-weight: 700; font-size: 0.9rem; margin-bottom: 14px; text-transform: uppercase; letter-spacing: 2px; color: var(--soft); }
.sb-row { display: grid; grid-template-columns: 90px 1fr 34px; align-items: center; gap: 10px; margin-bottom: 10px; }
.sb-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-bar { height: 12px; background: rgba(255,255,255,0.1); border-radius: 999px; overflow: hidden; }
.sb-fill { height: 100%; background: linear-gradient(90deg, var(--cyan), var(--pink)); border-radius: 999px; }
.sb-score { font-family: 'Unbounded', sans-serif; font-weight: 800; text-align: right; }

/* ---------- Финал ---------- */
.screen[data-screen="gameover"] { justify-content: center; }
.winner-title { margin-bottom: 30px; font-size: 1.5rem; }
.podium { display: flex; align-items: flex-end; justify-content: center; gap: 10px; margin-bottom: 24px; min-height: 200px; }
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.podium-ava { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; font-family: 'Unbounded', sans-serif; font-weight: 800; font-size: 1.4rem; background: linear-gradient(140deg, var(--pink), var(--purple)); }
.podium-name { font-weight: 600; font-size: 0.85rem; max-width: 90px; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.podium-block { width: 90px; border-radius: 14px 14px 0 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 12px; gap: 4px; }
.podium-place { font-family: 'Unbounded', sans-serif; font-weight: 900; font-size: 1.6rem; }
.podium-score { font-size: 0.8rem; color: var(--soft); }
.place-1 .podium-block { height: 150px; background: linear-gradient(180deg, var(--yellow), rgba(255,217,60,0.2)); }
.place-1 .podium-ava { width: 68px; height: 68px; box-shadow: 0 0 30px var(--yellow); }
.place-2 .podium-block { height: 110px; background: linear-gradient(180deg, var(--cyan), rgba(0,224,255,0.2)); }
.place-3 .podium-block { height: 80px; background: linear-gradient(180deg, var(--pink), rgba(255,60,172,0.2)); }
.final-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.final-row { display: flex; justify-content: space-between; background: var(--glass); border: 1px solid var(--glass-brd); border-radius: 14px; padding: 12px 18px; font-weight: 600; }
.final-row.winner { background: linear-gradient(120deg, rgba(255,217,60,0.2), rgba(255,60,172,0.15)); border-color: rgba(255,217,60,0.4); }
.final-row b { font-family: 'Unbounded', sans-serif; }

/* ---------- Конфетти ---------- */
#confetti-layer { position: fixed; inset: 0; pointer-events: none; z-index: 100; overflow: hidden; }
.confetti { position: absolute; top: -20px; border-radius: 2px; }

/* ---------- Прочее ---------- */
.sound-toggle { position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px; z-index: 50;
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--glass-brd); background: var(--glass);
  backdrop-filter: blur(10px); font-size: 1.1rem; cursor: pointer; }
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); z-index: 200;
  background: rgba(20,0,40,0.92); border: 1px solid var(--glass-brd); backdrop-filter: blur(12px);
  padding: 14px 22px; border-radius: 14px; font-weight: 600; font-size: 0.9rem; opacity: 0; pointer-events: none;
  max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }

@media (max-height: 700px) {
  .logo-word { font-size: 3.2rem; }
  .prompt-card { font-size: 1.2rem; padding: 22px 18px; }
  .podium { min-height: 170px; }
}
