/* ===== پایه و متغیرها ===== */
:root {
  --bg-0: #0f0a24;
  --bg-1: #1a1040;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f4f1ff;
  --text-dim: #b9b2d8;
  --brand: #ff3d81;
  --brand-2: #7b5cff;
  --accent: #23d5ab;
  --gold: #ffd93d;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --radius: 20px;
  --radius-sm: 12px;
}

[data-theme="light"] {
  --bg-0: #eef1ff;
  --bg-1: #f7e9ff;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-strong: rgba(255, 255, 255, 0.9);
  --border: rgba(30, 20, 70, 0.12);
  --text: #241a45;
  --text-dim: #6a608c;
  --shadow: 0 20px 60px rgba(80, 40, 140, 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: "Vazirmatn", "Tahoma", "Segoe UI", sans-serif;
  direction: rtl;
  color: var(--text);
  background: linear-gradient(160deg, var(--bg-0), var(--bg-1));
  background-attachment: fixed;
  overflow-x: hidden;
  min-height: 100vh;
  transition: color 0.4s, background 0.6s;
}

/* ===== حباب‌های پس‌زمینه ===== */
.bg-blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.5;
  animation: float 18s ease-in-out infinite;
}
.b1 { width: 40vw; height: 40vw; background: var(--brand); top: -8vw; right: -6vw; }
.b2 { width: 34vw; height: 34vw; background: var(--brand-2); bottom: -8vw; left: -6vw; animation-delay: -6s; }
.b3 { width: 26vw; height: 26vw; background: var(--accent); top: 40%; left: 30%; animation-delay: -12s; opacity: 0.35; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(3vw, -3vw) scale(1.12); }
}

/* ===== هدر ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(16px, 4vw, 48px);
  max-width: 1240px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo {
  font-size: 40px;
  filter: drop-shadow(0 6px 14px rgba(255, 61, 129, 0.5));
  animation: bob 4s ease-in-out infinite;
}
@keyframes bob { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
.brand-text h1 { margin: 0; font-size: clamp(20px, 3vw, 30px); font-weight: 900; letter-spacing: -0.5px; }
.brand-text p { margin: 2px 0 0; font-size: 13px; color: var(--text-dim); }

.header-actions { display: flex; gap: 10px; }
.icon-btn {
  width: 46px; height: 46px;
  border: 1px solid var(--border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: 14px;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
  display: grid; place-items: center;
}
.icon-btn:hover { transform: translateY(-2px); background: var(--panel-strong); box-shadow: var(--shadow); }
.icon-btn .ico-off { display: none; }
.icon-btn.off .ico-on { display: none; }
.icon-btn.off .ico-off { display: inline; }

/* ===== چیدمان ===== */
.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 8px clamp(16px, 4vw, 48px) 48px;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 28px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ===== استیج گردونه ===== */
.stage-col { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.wheel-stage { position: relative; width: 100%; max-width: 520px; aspect-ratio: 1; }
.wheel-wrap { position: absolute; inset: 0; display: grid; place-items: center; }

#wheel {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  box-shadow: 0 0 0 10px rgba(255,255,255,0.06), 0 30px 70px rgba(0,0,0,0.5),
    inset 0 0 40px rgba(0,0,0,0.25);
  cursor: pointer;
}

/* عقربه */
.wheel-pointer {
  position: absolute;
  top: -6px; left: 50%;
  transform: translateX(-50%);
  width: 46px; height: 60px;
  z-index: 5;
  filter: drop-shadow(0 6px 8px rgba(0,0,0,0.4));
  background: linear-gradient(180deg, #fff, #ffe27a);
  clip-path: polygon(50% 100%, 0 0, 100% 0);
}
.wheel-pointer::after {
  content: "";
  position: absolute;
  top: -8px; left: 50%; transform: translateX(-50%);
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), #ff8f3d);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* هاب مرکزی */
.center-hub {
  position: absolute;
  width: 22%; height: 22%;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.9);
  background: radial-gradient(circle at 35% 28%, #ffffff, #f0ecff 45%, #d9ccff);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4), inset 0 2px 6px rgba(255,255,255,0.95);
  transition: transform 0.15s;
  z-index: 4;
  display: grid;
  place-items: center;
  animation: hubPulse 2.6s ease-in-out infinite;
}
.center-hub:hover { transform: scale(1.08); }
.center-hub:active { transform: scale(0.95); }
@keyframes hubPulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(0,0,0,0.4), inset 0 2px 6px rgba(255,255,255,0.95), 0 0 0 0 rgba(255,61,129,0.45); }
  50% { box-shadow: 0 8px 24px rgba(0,0,0,0.4), inset 0 2px 6px rgba(255,255,255,0.95), 0 0 0 10px rgba(255,61,129,0); }
}
.hub-label {
  font-family: "Vazirmatn", "Tahoma", sans-serif;
  font-weight: 900;
  font-size: clamp(13px, 2.6vw, 19px);
  letter-spacing: 0.5px;
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  text-shadow: none;
  pointer-events: none;
}

/* ===== دکمه‌ها ===== */
.stage-actions { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 14px; }
.btn {
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  color: var(--text);
  background: var(--panel);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, background 0.2s, opacity 0.2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:hover { transform: translateY(-2px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn.sm { padding: 9px 14px; font-size: 13.5px; }

.btn-spin {
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
  border: none;
  font-size: 19px;
  padding: 18px;
  box-shadow: 0 14px 34px rgba(255, 61, 129, 0.4);
  color: #fff;
}
.btn-spin:hover { box-shadow: 0 18px 42px rgba(255, 61, 129, 0.55); }
/* فقط آیکون متحرک می‌ماند */
.spin-ico { font-size: 22px; display: inline-block; animation: spinIco 2.4s ease-in-out infinite; }
@keyframes spinIco { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(20deg); } }

.btn-ghost { background: var(--panel); }
.btn-ghost:hover { background: var(--panel-strong); }
.mini-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }

/* ===== پنل کنترل ===== */
.panel {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.tabs { display: flex; gap: 2px; padding: 8px; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1;
  font-family: inherit;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 11px 6px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: var(--panel-strong); }
.tab.is-active { color: #fff; background: linear-gradient(120deg, var(--brand), var(--brand-2)); }

.tab-panel { display: none; padding: 20px; animation: fade 0.3s ease; }
.tab-panel.is-active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; }
.panel-head label { font-weight: 700; font-size: 14.5px; }
.count-badge {
  background: var(--panel-strong);
  border: 1px solid var(--border);
  padding: 4px 12px; border-radius: 999px; font-size: 13px; color: var(--text-dim);
}
.count-badge b { color: var(--brand); font-size: 15px; }

.names-input {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  font-family: inherit;
  font-size: 15px;
  line-height: 2;
  color: var(--text);
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  direction: rtl;
}
[data-theme="light"] .names-input { background: rgba(255,255,255,0.6); }
.names-input:focus { outline: 2px solid var(--brand-2); border-color: transparent; }

.input-tools { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.hint { font-size: 12.5px; color: var(--text-dim); margin: 14px 0 0; line-height: 1.8; }

/* جعبهٔ ایمپورت فایل */
.import-box {
  margin-top: 16px;
  padding: 15px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
}
[data-theme="light"] .import-box { background: rgba(123, 92, 255, 0.05); }
.import-head { font-weight: 800; font-size: 14px; margin-bottom: 5px; }
.import-desc { font-size: 12.5px; color: var(--text-dim); margin: 0 0 12px; line-height: 1.8; }
.import-desc b { color: var(--accent); }
.btn-import {
  width: 100%;
  background: linear-gradient(120deg, rgba(35, 213, 171, 0.28), rgba(123, 92, 255, 0.28));
  border: 1px solid var(--border);
}
.btn-import:hover { background: linear-gradient(120deg, rgba(35, 213, 171, 0.42), rgba(123, 92, 255, 0.42)); }

/* ===== لیست‌ها ===== */
.saved-list, .history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.saved-item, .history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--panel-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
}
.saved-item .s-info b { display: block; font-size: 14.5px; }
.saved-item .s-info small { color: var(--text-dim); font-size: 12px; }
.saved-item .s-actions { display: flex; gap: 6px; }
.chip-btn {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: 8px; padding: 6px 10px; font-size: 12.5px; font-family: inherit; cursor: pointer; font-weight: 700;
  transition: background 0.2s;
}
.chip-btn:hover { background: var(--panel); }
.chip-btn.danger:hover { background: rgba(255, 61, 129, 0.2); color: var(--brand); }

.history-item { font-size: 14px; }
.history-item .rank { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-weight: 900; font-size: 12px; background: var(--gold); color: #4a3500; }
.history-item .h-name { flex: 1; font-weight: 700; }
.history-item .h-time { color: var(--text-dim); font-size: 11.5px; }

/* ===== تنظیمات ===== */
.setting-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border-bottom: none; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.setting-row b { font-size: 14.5px; }
.setting-row small { display: block; color: var(--text-dim); font-size: 12px; margin-top: 3px; }
.row-label { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }

input[type="range"] {
  width: 100%; height: 6px; border-radius: 999px; -webkit-appearance: none; appearance: none;
  background: linear-gradient(90deg, var(--brand), var(--brand-2)); cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 3px solid var(--brand); box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* سوییچ */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: rgba(120,120,140,0.4); border-radius: 999px; transition: 0.3s; }
.slider::before { content: ""; position: absolute; height: 22px; width: 22px; right: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.3s; }
.switch input:checked + .slider { background: linear-gradient(120deg, var(--brand), var(--brand-2)); }
.switch input:checked + .slider::before { transform: translateX(-22px); }

/* پالت رنگ */
.palette-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.palette-swatch {
  height: 42px; border-radius: 10px; cursor: pointer; border: 2px solid transparent;
  overflow: hidden; display: flex; transition: transform 0.15s;
}
.palette-swatch:hover { transform: scale(1.05); }
.palette-swatch.is-active { border-color: #fff; box-shadow: 0 0 0 2px var(--brand); }
.palette-swatch span { flex: 1; }

/* ===== مودال برنده ===== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(10, 6, 25, 0.72);
  backdrop-filter: blur(8px);
  display: grid; place-items: center;
  animation: fade 0.3s ease;
}
.modal-backdrop[hidden] { display: none; }
.winner-card {
  background: linear-gradient(160deg, rgba(255,255,255,0.12), rgba(255,255,255,0.04));
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  border-radius: 28px;
  padding: 40px 44px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  max-width: 90vw;
  animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.winner-emoji { font-size: 64px; animation: bob 2s ease-in-out infinite; }
.winner-sub { margin: 6px 0 0; color: var(--gold); font-weight: 700; letter-spacing: 2px; font-size: 14px; }

/* کادر رنگی چرخان دور اسم برنده */
@property --bd-angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
@keyframes rotate-border { to { --bd-angle: 360deg; } }
.winner-name-box {
  position: relative;
  display: inline-block;
  margin: 16px 0 28px;
  padding: 16px 34px;
  border-radius: 22px;
  background: rgba(10, 6, 25, 0.35);
}
.winner-name-box::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 22px;
  padding: 4px;
  background: conic-gradient(from var(--bd-angle),
    #ff3d81, #7b5cff, #23d5ab, #ffd93d, #ff8f3d, #4dabff, #ff3d81);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  animation: rotate-border 4.5s linear infinite;
  pointer-events: none;
}
.winner-name-box::after {
  content: "";
  position: absolute; inset: -6px;
  border-radius: 26px;
  background: conic-gradient(from var(--bd-angle),
    #ff3d81, #7b5cff, #23d5ab, #ffd93d, #ff8f3d, #4dabff, #ff3d81);
  filter: blur(18px);
  opacity: 0.55;
  z-index: -1;
  animation: rotate-border 4.5s linear infinite;
}
.winner-name {
  position: relative;
  margin: 0; font-size: clamp(30px, 6vw, 52px); font-weight: 900;
  background: linear-gradient(120deg, #fff, var(--gold), var(--brand));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  word-break: break-word;
}
.winner-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* کانفتی + توست */
.confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 70; }
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(20, 12, 45, 0.95); color: #fff; border: 1px solid var(--border);
  padding: 12px 22px; border-radius: 999px; font-size: 14px; font-weight: 700;
  z-index: 80; opacity: 0; transition: opacity 0.3s, transform 0.3s; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* باکس تبلیغات شیشه‌ای */
.ad-slot { max-width: 1240px; margin: 10px auto 0; padding: 8px clamp(16px, 4vw, 48px); }
.ad-box {
  position: relative;
  min-height: 120px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius);
  overflow: hidden;
}
/* تبلیغ واقعی (تصویر/آی‌فریم/کد) خودکار ریسپانسیو می‌شود */
.ad-box img, .ad-box iframe, .ad-box ins, .ad-box video {
  max-width: 100%; height: auto; display: block; border: 0;
}

/* حالت «جای خالی» — با درج تبلیغ واقعی، کلاس ad-placeholder را حذف کنید */
.ad-placeholder {
  border: 1.5px dashed var(--border);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}
.ad-placeholder::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(120deg, transparent 30%, rgba(255, 255, 255, 0.12) 50%, transparent 70%);
  background-size: 200% 100%;
  animation: adShine 4.5s linear infinite;
  pointer-events: none;
}
@keyframes adShine { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.ad-badge {
  position: absolute; top: 12px; right: 12px;
  font-size: 11px; font-weight: 700; color: var(--text-dim);
  background: var(--panel-strong); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px;
}
.ad-text { margin: 0; font-size: clamp(16px, 3vw, 22px); font-weight: 800; color: var(--text-dim); }
body.focus-wheel .ad-slot { display: none; }

/* فوتر */
.app-footer {
  text-align: center;
  padding: 34px 20px 44px;
  max-width: 900px;
  margin: 10px auto 0;
  border-top: 1px solid var(--border);
}
.footer-main { font-size: 15.5px; font-weight: 800; color: var(--text); margin: 0 0 8px; }
.footer-sub { font-size: 13px; color: var(--text-dim); margin: 0; }
.footer-sub a {
  color: var(--brand);
  text-decoration: none;
  font-weight: 800;
  border-bottom: 1px dashed transparent;
  transition: border-color 0.2s;
}
.footer-sub a:hover { border-bottom-color: var(--brand); }
.footer-sub .heart { display: inline-block; animation: heartbeat 1.4s ease-in-out infinite; }
@keyframes heartbeat { 0%,100%{transform:scale(1)} 15%{transform:scale(1.25)} 30%{transform:scale(1)} 45%{transform:scale(1.18)} }
body.focus-wheel .app-footer { display: none; }

/* استپر تعداد برندگان */
.stepper { display: flex; align-items: center; gap: 8px; }
.step-btn {
  width: 38px; height: 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--panel-strong);
  color: var(--text); font-size: 20px; font-weight: 800;
  cursor: pointer; font-family: inherit; transition: background 0.2s, transform 0.1s;
}
.step-btn:hover { background: var(--panel); }
.step-btn:active { transform: scale(0.92); }
#winnersCount {
  width: 56px; height: 38px; text-align: center;
  font-family: inherit; font-size: 16px; font-weight: 800;
  border-radius: 10px; border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18); color: var(--text);
}
[data-theme="light"] #winnersCount { background: rgba(255, 255, 255, 0.6); }
#winnersCount::-webkit-outer-spin-button,
#winnersCount::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
#winnersCount { -moz-appearance: textfield; }

/* فهرست چند برنده در مودال */
.winners-list {
  list-style: none; margin: 16px 0 26px; padding: 4px;
  display: flex; flex-wrap: wrap; gap: 12px; justify-content: center;
  max-width: 540px; max-height: 46vh; overflow-y: auto;
}
.winners-list li {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 20px; border-radius: 15px;
  background: rgba(10, 6, 25, 0.4);
  font-size: clamp(16px, 3.4vw, 24px); font-weight: 800;
}
.winners-list li::before {
  content: ""; position: absolute; inset: 0; border-radius: 15px; padding: 3px;
  background: conic-gradient(from var(--bd-angle),
    #ff3d81, #7b5cff, #23d5ab, #ffd93d, #ff8f3d, #4dabff, #ff3d81);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask-composite: exclude;
  animation: rotate-border 4.5s linear infinite; pointer-events: none;
}
.winners-list .w-rank {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  background: var(--gold); color: #4a3500; font-size: 13px; font-weight: 900;
}
.winners-list .w-name {
  background: linear-gradient(120deg, #fff, var(--gold), var(--brand));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

/* حالت تمرکز روی گردونه */
body.focus-wheel .panel, body.focus-wheel .app-header .brand-text p { display: none; }
body.focus-wheel .layout { grid-template-columns: 1fr; }
body.focus-wheel .wheel-stage { max-width: min(78vh, 720px); }
body.focus-wheel .stage-actions { max-width: min(78vh, 720px); }
