/* Всё в цветах Telegram (docs/design-variants, варианты tgdark и tglight).
   Внутри Telegram семь переменных --tg-* приходят из themeParams (app.js); снаружи тема
   выбирается по prefers-color-scheme, и работают запасные значения ниже. Класс .light/.dark
   на <html> ставит app.js (из colorScheme в Telegram или из prefers-color-scheme в браузере). */
:root {
  --bg: var(--tg-bg, #17212b);
  --surface: var(--tg-secondary-bg, #232e3c);
  --text: var(--tg-text, #f5f5f5);
  --muted: var(--tg-hint, #8a9aa9);
  --accent: var(--tg-link, #5eb5f7);
  --ring-color: var(--tg-button, #5eb5f7);
  --destructive: var(--tg-destructive, #ff5a5a);
  --live: var(--accent);
  --line: rgba(255, 255, 255, 0.08);
  --card-shadow: none;
  --ring-track: #0e1621;
  --ring-glow: rgba(94, 181, 247, 0.35);
  --ring-text: #0e1621;
  --btn-hi: #8fd8ff;
  --btn: #2aabee;
  --btn-lo: #0f5f9c;
  --btn-text: #ffffff;
  --rim: #0e1621;
  --rim2: #2b5278;
  --btn-glow: rgba(42, 171, 238, 0.45);
  --av: #2b5278;
  --av-text: #cfe6ff;
  --lead-av-text: #0e1621;
  --ok: #8ef0a4;
  --glow: 0.4;   /* сила свечения вокруг кнопки, в hot = 1 */
  --press: 0px;
  --ring: 100%;  /* заполнение кольца-таймера */
}
/* светлая тема: по prefers-color-scheme до того, как отработал скрипт, и по классу .light после */
@media (prefers-color-scheme: light) {
  :root:not(.dark) {
    --bg: var(--tg-bg, #efeff4);
    --surface: var(--tg-secondary-bg, #ffffff);
    --text: var(--tg-text, #000000);
    --muted: var(--tg-hint, #8e8e93);
    --accent: var(--tg-link, #2481cc);
    --ring-color: var(--tg-button, #2481cc);
    --line: rgba(0, 0, 0, 0.1);
    --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    --ring-track: #e5e5ea;
    --ring-glow: rgba(36, 129, 204, 0.25);
    --ring-text: #ffffff;
    --btn-lo: #1a73b8;
    --rim: #ffffff;
    --rim2: #d1d1d6;
    --btn-glow: rgba(42, 171, 238, 0.35);
    --av: #e5e5ea;
    --av-text: #3c3c43;
    --lead-av-text: #ffffff;
    --ok: #1f8a3c;
  }
}
:root.light {
  --bg: var(--tg-bg, #efeff4);
  --surface: var(--tg-secondary-bg, #ffffff);
  --text: var(--tg-text, #000000);
  --muted: var(--tg-hint, #8e8e93);
  --accent: var(--tg-link, #2481cc);
  --ring-color: var(--tg-button, #2481cc);
  --line: rgba(0, 0, 0, 0.1);
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --ring-track: #e5e5ea;
  --ring-glow: rgba(36, 129, 204, 0.25);
  --ring-text: #ffffff;
  --btn-lo: #1a73b8;
  --rim: #ffffff;
  --rim2: #d1d1d6;
  --btn-glow: rgba(42, 171, 238, 0.35);
  --av: #e5e5ea;
  --av-text: #3c3c43;
  --lead-av-text: #ffffff;
  --ok: #1f8a3c;
}

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

html, body {
  margin: 0;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", Inter, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

html, body { background: var(--bg); }
body { min-height: 100dvh; }

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.eyebrow {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ---------- шапка ---------- */
.top { text-align: center; padding-top: 6px; }
.fund {
  display: inline-block;
  font-size: 50px;
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.1;
  margin-top: 4px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.fund .unit { font-size: 18px; font-weight: 700; margin-left: 8px; color: var(--muted); }
.fund.bump { animation: bump 0.5s ease-out; }
@keyframes bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.1); text-shadow: 0 0 24px rgba(255, 255, 255, 0.45); }
  100% { transform: scale(1); }
}
.round-tag {
  display: block;
  width: fit-content;
  margin: 8px auto 0;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.app[data-phase="round"] .round-tag { color: var(--text); }
.app[data-phase="round"] .round-tag::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 8px var(--live);
  margin-right: 7px;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { opacity: 0.3; } }

/* ---------- панели по фазам ---------- */
.panel { display: none; text-align: center; }
.app[data-phase="lobby"]  .panel-lobby,
.app[data-phase="round"]  .panel-round,
.app[data-phase="result"] .panel-result { display: block; }

.countdown {
  font-size: 46px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  margin: 4px 0 10px;
}
.commit {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.commit code {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.commit[hidden] { display: none; }
.presence { font-size: 14px; color: var(--muted); line-height: 1.5; }
.presence b { color: var(--text); font-weight: 600; }
.last-winner { margin-top: 10px; font-size: 14px; color: var(--muted); }
.last-winner b { color: var(--accent); }

/* лидер */
.leader-chip {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
  padding: 10px 20px;
  border-radius: 999px;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 18px color-mix(in srgb, var(--accent) 25%, transparent);
  font-size: 18px;
  font-weight: 700;
  min-width: 220px;
  justify-content: center;
  transition: box-shadow 0.3s, border-color 0.3s;
}
.leader-chip .name { color: var(--text); }
.leader-chip .time { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.leader-chip.free { border-color: var(--line); box-shadow: var(--card-shadow); }
.leader-chip.free .name { color: var(--muted); font-weight: 500; }
.app.hot .leader-chip { border-color: var(--destructive); box-shadow: 0 0 26px color-mix(in srgb, var(--destructive) 50%, transparent); }

/* результат */
.winner {
  font-size: 44px;
  font-weight: 900;
  margin-top: 2px;
  letter-spacing: -0.01em;
}
.winner-fund {
  display: inline-block;
  font-size: 44px;
  font-weight: 900;
  margin-top: 2px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 24px rgba(255, 255, 255, 0.25);
}
.winner-fund .unit { font-size: 18px; font-weight: 700; margin-left: 6px; color: var(--muted); }
.winner-fund.none { color: var(--muted); font-size: 18px; font-weight: 500; text-shadow: none; }
.reason {
  display: block;
  margin: 12px auto 0;
  width: fit-content;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  font-size: 13px;
  color: var(--text);
}
.reason.secret { background: color-mix(in srgb, var(--destructive) 18%, transparent); color: var(--destructive); }
.reveal {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  text-align: left;
  line-height: 1.5;
}
.reveal:empty { display: none; }
.reveal b { color: var(--text); }
.reveal code {
  display: block;
  word-break: break-all;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
}
.reveal .ok { color: var(--ok); font-weight: 600; }
.reveal .bad { color: var(--destructive); font-weight: 600; }
.next { margin-top: 10px; font-size: 14px; color: var(--muted); }
.next b { color: var(--text); font-variant-numeric: tabular-nums; }

/* ---------- кнопка с кольцом-таймером (docs/design-variants/buttons.html, № 8) ---------- */
.button-wrap {
  --size: min(60vw, 240px);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 10px 0 4px;
}
/* мягкое свечение вокруг кнопки; в последние 3 секунды разгорается */
.button-wrap::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(100vw, 460px);
  aspect-ratio: 1;
  transform: translate(-50%, -54%);
  border-radius: 50%;
  background: radial-gradient(circle, var(--halo) 0%, transparent 62%);
  filter: blur(8px);
  pointer-events: none;
  transition: opacity 0.4s;
}
.app { --halo: color-mix(in srgb, var(--btn) 22%, transparent); }
.app:not([data-phase="round"]) { --glow: 0; --halo: transparent; }
.app.hot { --glow: 1; --halo: color-mix(in srgb, var(--destructive) 55%, transparent); }

.ring-wrap {
  position: relative;
  width: calc(var(--size) + 56px);
  height: calc(var(--size) + 56px);
  display: flex;
  align-items: center;
  justify-content: center;
}
/* кольцо: conic-gradient, вырезанный маской в обод толщиной 10px; заполнение = остаток таймера */
.ring-track {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) 0 var(--ring), var(--ring-track) var(--ring) 100%);
  -webkit-mask: radial-gradient(circle closest-side, transparent calc(100% - 11px), #000 calc(100% - 10px));
  mask: radial-gradient(circle closest-side, transparent calc(100% - 11px), #000 calc(100% - 10px));
  box-shadow: 0 0 18px var(--ring-glow);
  pointer-events: none;
  transition: opacity 0.3s;
}
/* кнопка свободна: кольцо пустое и приглушённое */
.ring-wrap.idle { --ring: 0%; }
.ring-wrap.idle .ring-track { box-shadow: none; opacity: 0.6; }
/* последние 3 секунды: красное и пульсирует вместе с тряской кнопки */
.ring-wrap.hot { --ring-color: var(--destructive); }
.ring-wrap.hot .ring-track { animation: ring-pulse 0.35s infinite; box-shadow: 0 0 26px color-mix(in srgb, var(--destructive) 60%, transparent); }
@keyframes ring-pulse { 50% { opacity: 0.35; } }
.app:not([data-phase="round"]) .ring-track { opacity: 0.25; box-shadow: none; }
/* чип с секундами справа внизу кольца */
.ring-val {
  position: absolute;
  right: 0;
  bottom: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--ring-color);
  color: var(--ring-text);
  font-size: 13px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  z-index: 2;
}
.ring-wrap.idle .ring-val { background: var(--surface); color: var(--muted); box-shadow: none; }
.ring-wrap.hot .ring-val { background: var(--destructive); color: #fff; }
.app:not([data-phase="round"]) .ring-val { display: none; }

.big {
  position: relative;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  border: 0;
  cursor: pointer;
  color: var(--btn-text);
  font: 900 28px/1 -apple-system, BlinkMacSystemFont, "SF Pro Display", Inter, "Segoe UI", sans-serif;
  letter-spacing: 0.1em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  background: radial-gradient(circle at 38% 30%, var(--btn-hi) 0%, var(--btn) 42%, var(--btn-lo) 100%);
  --btn-shadow: var(--btn-glow);
  box-shadow:
    inset 0 -14px 24px rgba(0, 0, 0, 0.28),
    inset 0 8px 16px rgba(255, 255, 255, 0.18),
    0 0 0 7px var(--rim),
    0 0 0 10px var(--rim2),
    0 6px 0 7px var(--rim),
    0 14px 30px rgba(0, 0, 0, 0.35),
    0 0 50px var(--btn-shadow);
  transform: translateY(var(--press));
  transition: transform 0.06s ease-out, box-shadow 0.25s, filter 0.3s;
  user-select: none;
  touch-action: manipulation;
  outline: none;
}
/* глянцевый блик */
.big::before {
  content: "";
  position: absolute;
  left: 16%;
  top: 8%;
  width: 68%;
  height: 40%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0));
  pointer-events: none;
}
.big span { position: relative; display: block; transform: translateY(2px); }
.big.pressed, .big:active { --press: 8px; }
.big:disabled {
  cursor: default;
  filter: saturate(0.3) brightness(0.55);
}
.app.hot .big { animation: shake 0.11s infinite; --btn-shadow: color-mix(in srgb, var(--destructive) 85%, transparent); }
.app.hot { animation: screen-shake 0.16s infinite; }
@keyframes shake {
  0%   { transform: translate(0, var(--press)); }
  25%  { transform: translate(-3px, calc(var(--press) - 1px)) rotate(-0.6deg); }
  50%  { transform: translate(3px, calc(var(--press) + 1px)) rotate(0.6deg); }
  75%  { transform: translate(-2px, calc(var(--press) + 1px)); }
  100% { transform: translate(2px, var(--press)) rotate(-0.4deg); }
}
@keyframes screen-shake {
  0% { transform: translate(0, 0); }
  30% { transform: translate(1px, -1px); }
  60% { transform: translate(-1px, 1px); }
  100% { transform: translate(0, 0); }
}
.hint {
  position: relative;
  z-index: 1;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.4em;
  text-align: center;
}
.hint.flash { color: var(--accent); }

/* ---------- история ---------- */
.history { margin-top: 4px; }
.history ol { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1.5px solid transparent;
  box-shadow: var(--card-shadow);
  font-size: 15px;
}
.history li .av {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--av);
  color: var(--av-text);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.history li .name { flex: 1; }
.history li .time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.history li.leader {
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  border-color: var(--accent);
  box-shadow: 0 0 16px color-mix(in srgb, var(--accent) 25%, transparent);
}
.history li.leader .av { background: var(--accent); color: var(--lead-av-text); }
.history li.leader .name { color: var(--text); font-weight: 700; }
.history li.me .name::after { content: " (ты)"; color: var(--muted); font-weight: 400; font-size: 12px; }
.empty { color: var(--muted); font-size: 13px; padding: 10px; text-align: center; }
.empty[hidden] { display: none; }

/* ---------- футер «кто я» ---------- */
.me {
  margin-top: auto;
  padding-top: 10px;
  display: flex;
  justify-content: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.me b { color: var(--text); font-weight: 600; }
.me a { color: var(--accent); cursor: pointer; text-decoration: none; }

/* ---------- праздник на экране итога ---------- */
.flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  background: radial-gradient(circle at 50% 38%, rgba(255, 255, 255, 0.95) 0%, rgba(42, 171, 238, 0.5) 30%, rgba(42, 171, 238, 0) 68%);
}
.flash.on { animation: flash 1.1s ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 4;
}
.confetti i {
  position: absolute;
  top: -5vh;
  left: var(--x);
  width: var(--w);
  height: var(--h);
  border-radius: 2px;
  background: var(--c);
  opacity: 0;
  animation: confetti-fall var(--dur) var(--delay) cubic-bezier(0.25, 0.6, 0.6, 1) forwards;
}
@keyframes confetti-fall {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate3d(var(--dx), 112vh, 0) rotate(var(--rot)); opacity: 0.9; }
}

/* ---------- оверлей имени (только снаружи Telegram) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
}
.overlay[hidden] { display: none; }
.card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.card h1 { margin: 0; font-size: 42px; font-weight: 900; letter-spacing: -0.02em; }
.card h1 .dot { color: var(--btn); }
.card p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 10px 0 18px; }
.card input {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--text) 8%, transparent);
  color: var(--text);
  font-size: 18px;
  text-align: center;
  outline: none;
}
.card input:focus { border-color: var(--accent); }
.card button {
  width: 100%;
  margin-top: 10px;
  padding: 14px;
  border-radius: 12px;
  border: 0;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
.card .primary { background: linear-gradient(180deg, var(--btn-hi), var(--btn)); color: #fff; box-shadow: 0 8px 20px var(--btn-glow); }
.card .ghost { background: transparent; color: var(--muted); font-weight: 500; }

/* ---------- уведомления ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 20;
}
.toast[hidden] { display: none; }
.offline {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: 8px;
  text-align: center;
  background: var(--destructive);
  color: #fff;
  font-size: 13px;
  z-index: 30;
}
.offline[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .app.hot, .app.hot .big, .ring-wrap.hot .ring-track, .confetti i, .fund.bump { animation: none; }
}
