/* Culorile vin din tema Telegram a utilizatorului (--tg-theme-*).
   Valorile --f-* sunt rezerva pentru browser: tema implicită Telegram, light și „Night Blue”. */
:root {
  --f-bg: #ffffff;
  --f-bg2: #efeff4;
  --f-text: #000000;
  --f-hint: #8e8e93;
  --f-link: #2481cc;
  --f-btn: #2481cc;
  --f-btn-text: #ffffff;
  --f-header: #6d6d72;
  --f-sep: rgba(60, 60, 67, 0.2);

  --bg: var(--tg-theme-bg-color, var(--f-bg));
  --bg2: var(--tg-theme-secondary-bg-color, var(--f-bg2));
  --section: var(--tg-theme-section-bg-color, var(--bg));
  --text: var(--tg-theme-text-color, var(--f-text));
  --hint: var(--tg-theme-hint-color, var(--f-hint));
  --link: var(--tg-theme-link-color, var(--f-link));
  --btn: var(--tg-theme-button-color, var(--f-btn));
  --btn-text: var(--tg-theme-button-text-color, var(--f-btn-text));
  --header: var(--tg-theme-section-header-text-color, var(--f-header));
  --sep: var(--tg-theme-section-separator-color, var(--f-sep));

  --premium: linear-gradient(135deg, #6b93ff 0%, #976fff 50%, #e46ace 100%);
  --gold: linear-gradient(135deg, #ffd25e 0%, #ff9f0a 100%);
  --green: linear-gradient(135deg, #5ee07a 0%, #2fb350 100%);
  --row: 64px;
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --vh: var(--tg-viewport-stable-height, 100vh);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}
:root[data-scheme='dark'] {
  --f-bg: #17212b;
  --f-bg2: #0e1621;
  --f-text: #f5f5f5;
  --f-hint: #708499;
  --f-link: #6ab3f3;
  --f-btn: #5288c1;
  --f-header: #6ab3f3;
  --f-sep: rgba(255, 255, 255, 0.07);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { background: var(--bg2); }
body {
  min-height: var(--vh);
  font: 400 16px/1.3 var(--font);
  color: var(--text);
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
}
body.locked { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input { -webkit-user-select: text; user-select: text; }
.hidden { display: none !important; }

.screen { display: none; min-height: var(--vh); }
.screen.active { display: flex; animation: fadeIn 0.35s ease both; }

/* ---------- Avatar (culorile Telegram pentru cei fără poză) ---------- */
.av {
  position: relative; flex: none; display: grid; place-items: center;
  border-radius: 50%; overflow: hidden;
  font-weight: 600; letter-spacing: 0.01em; color: #fff;
}
.av img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.25s; }
.av img.loaded { opacity: 1; }

/* ---------- Insigna cu zar ---------- */
.dice-badge {
  position: relative; flex: none; width: 88px; height: 88px; display: grid; place-items: center;
  border-radius: 50%; background: var(--premium); color: #fff; overflow: hidden;
  box-shadow: 0 8px 24px rgba(151, 111, 255, 0.32);
}
.dice-badge svg { width: 50%; height: 50%; }
.dice-badge::after {
  content: ''; position: absolute; top: 0; left: -80%; width: 50%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.45), transparent);
  transform: skewX(-20deg); animation: shine 4.5s ease-in-out infinite;
}
.dice-badge.lg { width: 104px; height: 104px; }
.dice-badge.muted { background: var(--section); color: var(--hint); box-shadow: none; font-size: 44px; }
.dice-badge.muted::after { display: none; }

/* ---------- Loader ---------- */
#loader { flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.loader-stage { position: relative; width: 240px; height: 220px; display: grid; place-items: center; }
.pulse { position: absolute; width: 104px; height: 104px; border-radius: 50%; background: var(--premium); opacity: 0; animation: pulse 2.4s ease-out infinite; }
.pulse.p2 { animation-delay: 1.2s; }
.badge-hold { position: relative; z-index: 2; }
.badge-hold.gulp { animation: gulp 0.26s ease; }
#loader.done .badge-hold { animation: happy 0.6s ease; }
.fly { position: absolute; left: 50%; top: 50%; margin: -16px 0 0 -16px; z-index: 1; box-shadow: 0 0 0 2px var(--bg2); }
.loader-title { margin-top: 4px; font-size: 20px; font-weight: 600; }
.loader-scan { margin-top: 6px; height: 20px; max-width: 280px; color: var(--hint); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.progress { position: relative; margin-top: 20px; width: min(240px, 70vw); height: 4px; border-radius: 2px; overflow: hidden; }
.progress::before { content: ''; position: absolute; inset: 0; background: var(--hint); opacity: 0.22; }
.progress i { position: relative; display: block; width: 0; height: 100%; border-radius: inherit; background: var(--btn); }
#loader.waiting .progress i { width: 32%; animation: indeterminate 1.1s ease-in-out infinite; }
.loader-count { margin-top: 20px; color: var(--hint); font-size: 14px; }
.loader-count b { display: block; margin-bottom: 2px; color: var(--text); font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* ---------- Home ---------- */
#home { flex-direction: column; width: 100%; max-width: 640px; margin: 0 auto; padding-bottom: calc(20px + var(--safe-bottom)); }
#home.has-bar { padding-bottom: calc(86px + var(--safe-bottom)); }

.hero { position: relative; display: flex; flex-direction: column; align-items: center; padding: 30px 24px 24px; text-align: center; }
.demo-pill { position: absolute; top: 14px; left: 16px; padding: 5px 10px; border-radius: 99px; background: var(--section); color: var(--link); font-size: 12px; font-weight: 600; }
.icon-btn { position: absolute; top: 10px; right: 16px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--section); color: var(--hint); }
.icon-btn svg { width: 18px; height: 18px; }
.hero-title { margin-top: 16px; font-size: 24px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; text-wrap: balance; }
.hero-sub { margin-top: 6px; color: var(--hint); font-size: 15px; }
.stack-row { margin-top: 16px; display: inline-flex; align-items: center; gap: 10px; padding: 5px 14px 5px 5px; border-radius: 99px; background: var(--section); font-size: 15px; font-weight: 600; }
.stack { display: flex; }
.stack .av { box-shadow: 0 0 0 2px var(--section); animation: pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1) both; }
.stack .av + .av { margin-left: -8px; }

.group { margin: 0 16px 24px; }
.section-header { padding: 0 16px 7px; color: var(--header); font-size: 13px; font-weight: 500; letter-spacing: 0.02em; text-transform: uppercase; }
.section { background: var(--section); border-radius: 12px; overflow: hidden; }
.section-footer { padding: 7px 16px 0; color: var(--hint); font-size: 13px; line-height: 1.38; }

.cell { display: flex; align-items: center; gap: 12px; min-height: 56px; padding-left: 16px; }
.cell-body { flex: 1; min-width: 0; align-self: stretch; display: flex; align-items: center; gap: 10px; padding: 8px 16px 8px 0; }
.cell + .cell > .cell-body { border-top: 0.5px solid var(--sep); }
.cell-text { flex: 1; min-width: 0; }
.cell-title { font-size: 16px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-sub { margin-top: 2px; color: var(--hint); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-end { flex: none; font-size: 22px; line-height: 1; }

.status-icon { flex: none; width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--green); }
.status-icon svg { width: 22px; height: 22px; }
.status-icon.premium { background: var(--premium); }
.status-icon.gold { background: var(--gold); }
.status-icon.muted { background: var(--hint); }
#statusCell.clickable { cursor: pointer; }
#statusCell.clickable:active { opacity: 0.7; }
#statusCell.clickable .cell-body::after { content: '›'; flex: none; color: var(--hint); font-size: 24px; line-height: 1; }

.tag { position: relative; isolation: isolate; flex: none; padding: 3px 8px; border-radius: 99px; color: var(--btn); font-size: 12px; font-weight: 600; }
.tag::before { content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: currentColor; opacity: 0.12; }

.search-wrap { position: relative; display: block; padding: 8px 12px; }
.search-wrap svg { position: absolute; left: 22px; top: 50%; width: 16px; height: 16px; margin-top: -8px; color: var(--hint); pointer-events: none; }
.search {
  width: 100%; height: 36px; padding: 0 12px 0 32px; border: 0; border-radius: 10px; outline: none;
  background: var(--bg2); color: var(--text); font: 400 16px var(--font);
  -webkit-appearance: none; appearance: none;
}
.search::placeholder { color: var(--hint); }
.search::-webkit-search-decoration { display: none; }
#plist .cell:first-child > .cell-body { border-top: 0.5px solid var(--sep); }
.list-note { padding: 14px 16px; border-top: 0.5px solid var(--sep); color: var(--hint); font-size: 14px; text-align: center; }

/* ---------- Butoane ---------- */
.main-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px 16px calc(10px + var(--safe-bottom));
  background: var(--bg); box-shadow: 0 -0.5px 0 var(--sep);
}
.main-bar .main-btn { max-width: 608px; margin: 0 auto; }
.main-btn {
  position: relative; overflow: hidden; width: 100%; height: 50px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; background: var(--btn); color: var(--btn-text);
  font-size: 17px; font-weight: 600; transition: opacity 0.15s, transform 0.15s;
}
.main-btn::after {
  content: ''; position: absolute; top: 0; left: -60%; width: 40%; height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.28), transparent);
  transform: skewX(-20deg); animation: shine 3.6s ease-in-out infinite;
}
.main-btn:active { opacity: 0.85; transform: scale(0.985); }
.main-btn:disabled { opacity: 0.45; cursor: default; }
.main-btn:disabled::after { display: none; }
.text-btn { width: 100%; height: 46px; border-radius: 12px; color: var(--link); font-size: 17px; font-weight: 500; }
.text-btn:active { opacity: 0.6; }
.secondary-btn {
  position: relative; isolation: isolate; width: 100%; height: 50px; border-radius: 12px;
  color: var(--btn); font-size: 17px; font-weight: 600; transition: opacity 0.15s, transform 0.15s;
}
.secondary-btn::before { content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit; background: currentColor; opacity: 0.12; }
.secondary-btn:active { opacity: 0.7; transform: scale(0.985); }

/* ---------- Mesaj ---------- */
#message { flex-direction: column; align-items: center; justify-content: center; padding: 32px 28px; text-align: center; }
.msg-title { margin-top: 20px; font-size: 20px; font-weight: 600; }
.msg-text { margin-top: 8px; max-width: 320px; color: var(--hint); font-size: 15px; line-height: 1.45; }
#message .main-btn { max-width: 260px; margin-top: 24px; }

/* ---------- Overlay-uri ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center;
  padding: 16px 16px calc(12px + var(--safe-bottom));
  background: var(--bg2);
  opacity: 0; visibility: hidden; transition: opacity 0.3s, visibility 0s 0.3s;
}
.overlay.open { opacity: 1; visibility: visible; transition: opacity 0.3s; }

/* ---------- Extragerea ---------- */
#draw { justify-content: center; }
.draw-head { margin-bottom: 28px; text-align: center; }
.draw-head h2 { font-size: 22px; font-weight: 700; }
.phase { min-height: 20px; margin-top: 6px; color: var(--hint); font-size: 15px; }
.reel-wrap { position: relative; width: min(100%, 420px); height: calc(var(--row) * 5); }
.reel-viewport {
  position: absolute; inset: 0; overflow: hidden; transition: opacity 0.35s, filter 0.35s;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 32%, #000 68%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 32%, #000 68%, transparent 100%);
}
#draw.counting .reel-viewport { opacity: 0.25; filter: blur(3px); }
.reel { padding-top: calc(var(--row) * 2); will-change: transform; }
.reel-row { height: var(--row); display: flex; align-items: center; gap: 12px; padding: 0 16px; will-change: transform, opacity; }
.reel-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.reel-name { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color 0.2s; }
.reel-user { color: var(--hint); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reel-row.win .reel-name { color: var(--btn); }
.reel-frame {
  position: absolute; left: 0; right: 0; top: calc(var(--row) * 2); height: var(--row); z-index: 2;
  border: 2px solid var(--btn); border-radius: 14px; pointer-events: none;
}
.reel-frame::before { content: ''; position: absolute; inset: 0; border-radius: 12px; background: var(--btn); opacity: 0.09; }
.reel-frame::after { content: ''; position: absolute; inset: -2px; border: 2px solid var(--btn); border-radius: 14px; opacity: 0; }
.reel-frame.flash::after { animation: ripple 0.9s ease-out; }
.countdown {
  position: absolute; inset: 0; z-index: 3; display: grid; place-items: center; pointer-events: none;
  color: var(--btn); font-size: 96px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.countdown.go { animation: count 0.8s cubic-bezier(0.2, 1.2, 0.3, 1) both; }
.draw-meta { margin-top: 28px; color: var(--hint); font-size: 14px; text-align: center; }

/* ---------- Persoana aleasă ---------- */
#result { overflow-x: hidden; overflow-y: auto; }
.result-card { min-height: min-content; }
.result-card { flex: 1; width: min(100%, 420px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding-top: 12px; text-align: center; }
.result-avatar { position: relative; width: 124px; height: 124px; display: grid; place-items: center; }
.result-glow { position: absolute; inset: -50px; border-radius: 50%; background: var(--premium); filter: blur(46px); opacity: 0.32; }
.result-ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 0deg, #6b93ff, #976fff, #e46ace, #ffb35c, #6b93ff);
  -webkit-mask: radial-gradient(circle, transparent 57px, #000 58px);
  mask: radial-gradient(circle, transparent 57px, #000 58px);
  animation: spin 4s linear infinite;
}
.result-avatar-inner { position: relative; z-index: 1; }
.result-badge {
  position: absolute; right: 0; bottom: 2px; z-index: 2; width: 36px; height: 36px;
  display: grid; place-items: center; border-radius: 50%; background: var(--gold);
  font-size: 18px; box-shadow: 0 0 0 3px var(--bg2);
}
.result-title { margin-top: 22px; color: var(--hint); font-size: 15px; }
.result-name { margin-top: 4px; font-size: 26px; font-weight: 700; line-height: 1.2; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.result-user { margin-top: 4px; color: var(--link); font-size: 16px; }
.result-details { width: 100%; margin-top: 26px; text-align: left; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 46px; margin-left: 16px; padding-right: 16px; font-size: 16px; }
.row + .row { border-top: 0.5px solid var(--sep); }
.row b { min-width: 0; color: var(--hint); font-weight: 400; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.result-actions { width: min(100%, 420px); display: grid; gap: 8px; padding-top: 16px; }

/* Previzualizarea mesajului din grup — arată ca un mesaj Telegram */
.result-preview { width: 100%; margin-top: 22px; text-align: left; }
.preview-note { display: flex; gap: 8px; align-items: flex-start; margin: 0 4px 18px; padding: 10px 12px; border-radius: 12px; background: var(--section); color: var(--hint); font-size: 13.5px; line-height: 1.35; }
.preview-note svg { flex: none; width: 16px; height: 16px; margin-top: 1px; }
.tg-chat { padding: 14px 10px; border-radius: 14px; background: linear-gradient(135deg, rgba(107, 147, 255, 0.16), rgba(151, 111, 255, 0.11) 50%, rgba(228, 106, 206, 0.14)); }
.tg-msg { display: flex; align-items: flex-end; gap: 8px; }
.tg-avatar { flex: none; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; background: var(--premium); color: #fff; }
.tg-avatar svg { width: 19px; height: 19px; }
.tg-bubble { min-width: 0; max-width: 88%; padding: 7px 11px 6px; border-radius: 16px 16px 16px 4px; background: var(--section); box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08); }
.tg-sender { margin-bottom: 2px; color: var(--link); font-size: 14px; font-weight: 600; }
.tg-text { font-size: 15.5px; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.tg-text .mention { color: var(--link); }
.tg-time { margin-top: 2px; color: var(--hint); font-size: 11.5px; text-align: right; }

#result.open .result-avatar { animation: popIn 0.7s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
#result.open .result-badge { animation: popIn 0.5s 0.45s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
#result.open .result-title,
#result.open .result-name,
#result.open .result-user { animation: rise 0.5s 0.2s ease both; }
#result.open .result-details,
#result.open .result-preview { animation: rise 0.5s 0.35s ease both; }
#result.open .result-actions { animation: rise 0.5s 0.5s ease both; }

#confetti { position: fixed; inset: 0; z-index: 30; width: 100%; height: 100%; pointer-events: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); z-index: 40;
  max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 12px;
  background: rgba(30, 30, 32, 0.92); color: #fff; font-size: 14px; font-weight: 500; text-align: center;
  opacity: 0; transform: translate(-50%, 12px); transition: opacity 0.25s, transform 0.25s; pointer-events: none;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Animații ---------- */
@keyframes fadeIn { from { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shine { 0%, 60% { left: -80%; } 100% { left: 140%; } }
@keyframes pulse { 0% { transform: scale(1); opacity: 0.32; } 100% { transform: scale(2.1); opacity: 0; } }
@keyframes gulp { 50% { transform: scale(1.07); } }
@keyframes happy { 40% { transform: scale(1.12) rotate(-5deg); } 70% { transform: scale(0.97) rotate(3deg); } }
@keyframes pop { from { transform: scale(0); opacity: 0; } }
@keyframes popIn { from { transform: scale(0.4); opacity: 0; } }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }
@keyframes indeterminate { from { transform: translateX(-110%); } to { transform: translateX(320%); } }
@keyframes count { from { transform: scale(1.8); opacity: 0; } 55% { opacity: 1; } to { transform: scale(1); opacity: 0.85; } }
@keyframes ripple { from { opacity: 0.6; transform: scale(1); } to { opacity: 0; transform: scale(1.06, 1.45); } }

@media (max-height: 640px) {
  :root { --row: 58px; }
  .draw-head { margin-bottom: 18px; }
  .draw-meta { margin-top: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .dice-badge::after, .main-btn::after, .pulse, .result-ring { animation: none !important; }
}
