:root {
  --bg: #0a0812;
  --card: #151029;
  --card-2: #1b1435;
  --text: #f0edf9;
  --muted: #a79dc9;
  --accent: #8b5cf6;
  --accent-2: #c4b5fd;
  --pink: #d946ef;
  --ok: #2fd07c;
  --err-bg: rgba(255, 107, 122, 0.12);
  --err-line: rgba(255, 107, 122, 0.45);
  --warn-bg: rgba(255, 200, 97, 0.12);
  --warn-line: rgba(255, 200, 97, 0.45);
  --radius: 18px;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  font-family: "Tajawal", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 85% -10%, rgba(139, 92, 246, 0.24), transparent 60%),
    radial-gradient(900px 500px at 5% 110%, rgba(56, 208, 224, 0.10), transparent 55%),
    var(--bg);
  padding: calc(34px + env(safe-area-inset-top, 0px))
           calc(16px + env(safe-area-inset-right, 0px))
           calc(44px + env(safe-area-inset-bottom, 0px))
           calc(16px + env(safe-area-inset-left, 0px));
  line-height: 1.6;
}

.app { max-width: 640px; margin: 0 auto; }

.hidden { display: none !important; }

/* ---------- hero ---------- */
.hero { text-align: center; margin-bottom: 24px; }

.logo-img {
  width: 104px;
  height: 104px;
  border-radius: 26px;
  display: block;
  margin: 0 auto;
  box-shadow: 0 14px 44px rgba(139, 92, 246, 0.45);
  animation: floatIn 0.5s ease;
}

.hero h1 {
  font-size: clamp(28px, 7vw, 38px);
  font-weight: 800;
  margin-top: 14px;
  letter-spacing: 0.1em;
  direction: ltr;
  background: linear-gradient(180deg, #ffffff 10%, #e7e2f5 50%, #9d95b5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 14px rgba(139, 92, 246, 0.40));
}

.hero p { color: var(--muted); margin-top: 6px; font-size: 15px; }

/* ---------- cards & banners ---------- */
.card {
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.40);
}

.banner {
  border-radius: 14px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14.5px;
  animation: rise 0.25s ease;
}
.banner.error { background: var(--err-bg); border: 1px solid var(--err-line); }
.banner.warning { background: var(--warn-bg); border: 1px solid var(--warn-line); }

/* ---------- steps ---------- */
.step-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  margin: 4px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-label:not(:first-child) { margin-top: 18px; }

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  font-size: 13px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.40);
}

.section-label { margin: 18px 0 8px; font-size: 14px; color: var(--muted); font-weight: 700; }

.hint { color: var(--muted); font-size: 13px; margin-top: 10px; text-align: center; }

/* ---------- platform selector ---------- */
.platforms {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.plat {
  --p: var(--accent);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.30);
  border: 1.5px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 13px 6px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, color 0.16s ease,
    box-shadow 0.16s ease, background 0.16s ease;
}

.plat[data-platform="tiktok"] { --p: #25f4ee; }
.plat[data-platform="youtube"] { --p: #ff4d5e; }
.plat[data-platform="instagram"] { --p: #e1306c; }

.plat .plat-icon { color: inherit; display: flex; transition: color 0.16s, filter 0.16s; }
.plat svg { width: 27px; height: 27px; display: block; }

.plat:hover { transform: translateY(-2px); color: var(--text); border-color: rgba(255, 255, 255, 0.22); }
.plat:active { transform: translateY(0); }

.plat.active {
  color: #fff;
  border-color: var(--p);
  background: rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 0 1px var(--p), 0 10px 26px -12px var(--p);
}
.plat.active .plat-icon { color: var(--p); filter: drop-shadow(0 0 7px var(--p)); }

/* ---------- input ---------- */
.input-row { display: flex; gap: 10px; }

.input-row input {
  flex: 1;
  min-width: 0;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 12px 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-row input::placeholder { color: #6f6792; }
.input-row input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.28);
}

/* ---------- buttons ---------- */
.btn {
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  border: none;
  border-radius: 12px;
  padding: 12px 22px;
  cursor: pointer;
  color: #fff;
  transition: transform 0.12s, filter 0.15s, opacity 0.15s;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.08); }
.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  box-shadow: 0 10px 24px rgba(139, 92, 246, 0.38);
  white-space: nowrap;
}

.btn.cta {
  width: 100%;
  margin-top: 16px;
  background: linear-gradient(135deg, var(--accent), var(--pink));
  box-shadow: 0 12px 30px rgba(168, 85, 247, 0.42);
  font-size: 16px;
  padding: 14px 22px;
}

.btn.loading { position: relative; color: transparent; }
.btn.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---------- result ---------- */
.result-card { margin-top: 16px; animation: rise 0.3s ease; }

.preview {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.35);
  aspect-ratio: 16 / 9;
}
.preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.duration {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 8px;
  font-size: 13px;
  padding: 2px 9px;
  direction: ltr;
}

.meta { margin-top: 14px; }
.meta h2 {
  font-size: 17px;
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.badge {
  font-size: 12.5px;
  font-weight: 700;
  color: #ddd3ff;
  background: rgba(139, 92, 246, 0.18);
  border: 1px solid rgba(139, 92, 246, 0.45);
  border-radius: 999px;
  padding: 3px 11px;
}
.badge.ghost {
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.12);
  font-weight: 500;
}

/* ---------- quality list ---------- */
.qualities { display: grid; gap: 8px; }

.quality {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
}
.quality:hover { border-color: rgba(139, 92, 246, 0.55); transform: translateX(-2px); }
.quality input {
  accent-color: var(--accent);
  width: 17px;
  height: 17px;
  cursor: pointer;
}
.quality.selected {
  border-color: var(--accent);
  background: rgba(139, 92, 246, 0.14);
}
.q-label { font-weight: 700; font-size: 15px; flex: 1; }
.q-size { font-size: 12.5px; color: var(--muted); direction: ltr; }

/* ---------- progress ---------- */
.progress {
  margin-top: 16px;
  text-align: center;
  padding: 14px 0 4px;
  animation: rise 0.25s ease;
}
.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 10px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.progress-text { font-weight: 700; font-size: 15px; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  right: 50%;
  transform: translateX(50%);
  background: linear-gradient(135deg, var(--ok), #17b866);
  color: #05240f;
  font-weight: 700;
  font-size: 14.5px;
  border-radius: 999px;
  padding: 11px 22px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.50);
  animation: rise 0.3s ease;
  z-index: 50;
  max-width: calc(100vw - 32px);
  text-align: center;
}

/* ---------- footer ---------- */
.footer { text-align: center; margin-top: 30px; color: var(--muted); font-size: 13px; }
.footer .brand {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.12em;
  direction: ltr;
  color: #fff;
  margin-bottom: 6px;
}
.footer .brand span { color: var(--accent-2); }
.footer .tiny { opacity: 0.55; font-size: 11.5px; margin-top: 4px; }

/* ---------- account top bar ---------- */
.topbar {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
  min-height: 40px;
}
.guest-bar { display: flex; justify-content: center; width: 100%; }
.account-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  width: 100%;
  background: rgba(0, 0, 0, 0.30);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  padding: 7px 14px;
}
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid var(--accent); }
.user-name {
  font-size: 13.5px;
  font-weight: 700;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.quota-chip {
  font-size: 12.5px;
  font-weight: 800;
  background: rgba(139, 92, 246, 0.20);
  border: 1px solid rgba(139, 92, 246, 0.5);
  color: var(--accent-2);
  border-radius: 999px;
  padding: 3px 11px;
  direction: rtl;
}
.quota-chip.pro { background: rgba(47, 208, 124, 0.16); border-color: rgba(47, 208, 124, 0.5); color: var(--ok); }
.quota-chip.empty { background: var(--err-bg); border-color: var(--err-line); color: #ff8b98; }
.chip-link {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  padding: 3px 11px;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s;
}
.chip-link:hover { color: var(--text); border-color: rgba(255, 255, 255, 0.3); }
.btn.small { padding: 9px 16px; font-size: 13.5px; border-radius: 11px; }
.btn.ghost-btn {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
}

/* ---------- modals ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 16px;
  animation: rise 0.2s ease;
}
.modal-box {
  position: relative;
  background: linear-gradient(180deg, var(--card), var(--card-2));
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: var(--radius);
  padding: 26px 22px 22px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal-title { font-size: 19px; font-weight: 800; margin-bottom: 8px; }
.modal-close {
  position: absolute;
  top: 10px;
  left: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 17px;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }
.gbtn-wrap { display: flex; justify-content: center; margin-top: 16px; min-height: 44px; }
.gbtn-wrap iframe { border-radius: 8px; }
.sub-note { margin-top: 10px; line-height: 1.7; }

/* ---------- access-code login ---------- */
.code-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}
.code-form input {
  width: 100%;
  background: rgba(0, 0, 0, 0.32);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 11px;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 11px 14px;
  text-align: center;
  letter-spacing: 0.06em;
}
.code-form input::placeholder { color: var(--muted); letter-spacing: normal; }
.code-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.25);
}
.or-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  color: var(--muted);
  font-size: 12.5px;
}
.or-divider::before,
.or-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
}

/* ---------- fallback save card (mobile) ---------- */
.file-fallback {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  right: 50%;
  transform: translateX(50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--card-2), var(--card));
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  padding: 8px 8px 8px 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  z-index: 55;
  max-width: calc(100vw - 24px);
  animation: rise 0.25s ease;
}
.file-fallback a {
  color: var(--accent-2);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-fallback-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--muted);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  cursor: pointer;
  font-size: 14px;
}
.file-fallback-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.2); }
#limit-modal .btn.cta { margin-top: 14px; }
#limit-modal .ghost-btn { margin-top: 10px; width: 100%; }

/* ---------- kit download button ---------- */
.kit-btn {
  margin-top: 14px;
  background: rgba(139, 92, 246, 0.14);
  border: 1.5px solid rgba(139, 92, 246, 0.5);
  color: var(--accent-2);
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 999px;
}
.kit-btn:hover { background: rgba(139, 92, 246, 0.26); }

/* ---------- animation ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes floatIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- responsive ---------- */
@media (max-width: 520px) {
  body { padding: 24px 12px 36px; }
  .card { padding: 16px; }
  .input-row { flex-direction: column; }
  .btn.primary { width: 100%; }
  .logo-img { width: 88px; height: 88px; border-radius: 22px; }
  .plat { font-size: 12.5px; padding: 11px 4px; }
  .plat svg { width: 24px; height: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
