:root {
  /* Fixed dark theme — the app has its own branded dark look, so text and
     surfaces don't follow the Telegram theme (which caused dark-on-dark text
     in light themes). */
  --bg: #0f1620;
  --bg2: #1b2533;
  --card: #1b2533;
  --text: #ffffff;
  --muted: #9aa7b4;
  --accent: #7C5CFF;
  --accent-text: #ffffff;
  --radius: 16px;
  --brand: linear-gradient(135deg, #7C5CFF 0%, #FF4FD8 52%, #FF8A3D 100%);
  --brand-soft: linear-gradient(135deg, rgba(124,92,255,.18), rgba(255,79,216,.14), rgba(255,138,61,.16));
  --line: rgba(255,255,255,.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; }
.logo { display: flex; filter: drop-shadow(0 4px 10px rgba(124,92,255,.4)); }
.wordmark { font-weight: 800; font-size: 18px; letter-spacing: -.3px; }
.balance-pill {
  display: flex; align-items: center; gap: 6px;
  background: var(--brand-soft);
  border: 1px solid var(--line);
  padding: 7px 13px; border-radius: 999px;
  font-weight: 700; font-size: 15px;
}
.balance-pill .gem { font-size: 13px; }

/* ---------- Layout ---------- */
#app { max-width: 600px; margin: 0 auto; padding: 16px 16px 96px; }
.screen { display: none; animation: fade .22s ease; }
.screen.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { font-size: 24px; margin: 2px 0 8px; letter-spacing: -.4px; }
h2 { font-size: 21px; margin: 2px 0 12px; letter-spacing: -.3px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.center {
  min-height: 62vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; gap: 12px;
}

.back {
  background: none; border: none; color: var(--muted);
  font-size: 15px; padding: 2px 0 10px; cursor: pointer;
}

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin-bottom: 14px; }
.hero { text-align: center; position: relative; overflow: hidden; }
.glow::before {
  content: ""; position: absolute; inset: -40% -20% auto; height: 220px;
  background: var(--brand); filter: blur(60px); opacity: .25; pointer-events: none;
}
.hero-badge {
  position: absolute; top: 14px; right: 14px;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 800;
  padding: 3px 9px; border-radius: 999px; letter-spacing: .5px;
}
.hero-emoji { font-size: 52px; position: relative; }

.notice {
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font-size: 14px; margin: 14px 0; text-align: left;
}
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.notice li { margin-bottom: 6px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: none; border-radius: var(--radius);
  padding: 15px 16px; font-size: 16px; font-weight: 700;
  cursor: pointer; margin-top: 12px; text-decoration: none; color: var(--text);
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.985); }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 8px 24px rgba(124,92,255,.32); }
.btn.secondary { background: var(--bg2); border: 1px solid var(--line); }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; }
.btn:disabled { opacity: .5; cursor: default; box-shadow: none; }
.btn.primary:disabled { background: var(--bg2); color: var(--muted); }

.topup {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg2); border: 1px solid var(--line); margin-top: 0; margin-bottom: 14px;
}
.topup .soon {
  font-size: 11px; font-weight: 800; letter-spacing: .5px;
  background: rgba(255,255,255,.08); color: var(--muted);
  padding: 3px 8px; border-radius: 999px;
}

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 12px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer;
}
.tile:active { transform: scale(.98); }
.tile-emoji { font-size: 26px; }

/* ---------- Upload ---------- */
.dropzone {
  display: block; position: relative; overflow: hidden;
  border: 2px dashed rgba(255,255,255,.2); border-radius: var(--radius);
  padding: 32px 16px; text-align: center; cursor: pointer; background: var(--card);
  transition: border-color .15s, background .15s;
}
.dropzone.filled { border-color: var(--accent); border-style: solid; background: var(--brand-soft); }
.dz-inner { pointer-events: none; }
.dz-emoji { font-size: 40px; }
.dz-inner p { margin: 8px 0 0; }
.file-overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; font-size: 0;
}
.or { text-align: center; color: var(--muted); margin: 16px 0 10px; font-size: 14px; position: relative; }
.or::before, .or::after { content: ""; position: absolute; top: 50%; width: 38%; height: 1px; background: var(--line); }
.or::before { left: 0; } .or::after { right: 0; }
.input {
  width: 100%; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; color: var(--text); font-size: 15px;
}
.input:focus { outline: none; border-color: var(--accent); }

/* ---------- Faces ---------- */
.faces-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin: 14px 0; }
.face { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; text-align: center; }
.face .pair { display: flex; align-items: center; justify-content: center; gap: 8px; }
.face .avatar { width: 66px; height: 66px; border-radius: 12px; object-fit: cover; background: rgba(255,255,255,.06); }
.face .arrow { color: var(--accent); font-size: 20px; font-weight: 700; }
.face .slot {
  position: relative; overflow: hidden; width: 66px; height: 66px; border-radius: 12px;
  border: 2px dashed rgba(255,255,255,.22); display: flex; align-items: center; justify-content: center;
  font-size: 24px; color: var(--muted); cursor: pointer;
}
.face .slot.filled { border-style: solid; border-color: var(--accent); }
.face .slot img { pointer-events: none; }
.face .label { font-size: 13px; color: var(--muted); margin-top: 10px; }

.field-label { font-size: 13px; color: var(--muted); margin: 6px 2px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 5px; }
.seg {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: none; border-radius: 12px; padding: 10px;
  color: var(--muted); cursor: pointer; font-size: 12px;
}
.seg b { font-size: 14px; color: var(--text); font-weight: 700; }
.seg.active { background: var(--brand); color: #fff; }
.seg.active b { color: #fff; }

.price-box {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; margin: 12px 0 0;
}
.price { font-weight: 800; font-size: 20px; }
.price::after { content: " 💎"; font-size: 14px; }

/* ---------- Processing ---------- */
.orb {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--brand); filter: blur(2px);
  animation: pulse 1.4s ease-in-out infinite; box-shadow: 0 0 40px rgba(255,79,216,.5);
}
@keyframes pulse { 0%,100% { transform: scale(.82); opacity: .7; } 50% { transform: scale(1.1); opacity: 1; } }

/* ---------- Result ---------- */
.result-head { display: flex; align-items: center; gap: 10px; }
.ok-badge {
  width: 30px; height: 30px; border-radius: 50%; background: var(--brand);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.result-video { width: 100%; border-radius: var(--radius); background: #000; margin: 6px 0; }
.dl-hint { text-align: center; margin: 10px 2px 0; }

/* ---------- History ---------- */
.hist-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
}
.hist-ic { font-size: 22px; width: 42px; height: 42px; border-radius: 11px; background: var(--bg2); display: flex; align-items: center; justify-content: center; }
.hist-main { flex: 1; min-width: 0; }
.hist-main b { font-size: 15px; }
.hist-sub { color: var(--muted); font-size: 13px; }
.hist-act { color: var(--accent); font-weight: 700; font-size: 14px; text-decoration: none; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------- Help ---------- */
.steps { list-style: none; margin: 4px 0 16px; padding: 0; }
.steps li { display: flex; gap: 12px; margin-bottom: 14px; }
.step-n {
  flex: none; width: 30px; height: 30px; border-radius: 50%; background: var(--brand);
  color: #fff; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.steps b { font-size: 15px; } .steps p { margin: 2px 0 0; }

/* ---------- Spinner / toast ---------- */
.spinner { width: 42px; height: 42px; border: 3px solid rgba(255,255,255,.15); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom));
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,.9); color: #fff; padding: 11px 18px; border-radius: 12px;
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  max-width: 90%; text-align: center; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: none; justify-content: space-around;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.tabbar.show { display: flex; }
.tab {
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; cursor: pointer; flex: 1; padding: 4px;
}
.tab span { font-size: 20px; filter: grayscale(.3); opacity: .8; }
.tab.active { color: var(--text); font-weight: 700; }
.tab.active span { filter: none; opacity: 1; }
