/* Uses Telegram's theme colours so the app matches each user's light/dark Telegram. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --text: var(--tg-theme-text-color, #16181b);
  --muted: var(--tg-theme-hint-color, #6b7280);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --accent: #0f9d58;
  --warn: #c77700;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg2); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
h1 { font-size: 22px; margin: 4px 0 2px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; padding: 48px 12px; }
.card { background: var(--bg); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.card.tap { cursor: pointer; display: block; color: inherit; text-decoration: none; }
.card.tap:active { opacity: .7; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.stat { background: var(--bg); border-radius: var(--radius); padding: 12px; text-align: center; }
.stat b { display: block; font-size: 22px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.pill { display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 99px; background: var(--bg2); white-space: nowrap; }
.pill.assigned { color: var(--link); }
.pill.in_progress { color: var(--warn); }
.pill.submitted, .pill.completed { color: var(--accent); }
.time { font-variant-numeric: tabular-nums; font-weight: 600; }
video { width: 100%; max-height: 62vh; background: #000; border-radius: var(--radius); display: block; }
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px; font: inherit; font-weight: 600; background: var(--btn); color: var(--btn-text); margin-top: 12px; }
.btn[disabled] { opacity: .5; }
.notice { background: var(--bg); border-left: 4px solid var(--warn); border-radius: 10px; padding: 12px 14px; margin: 10px 0; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--bg2); border-top-color: var(--btn); border-radius: 50%; margin: 0 auto 10px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn.secondary { background: var(--bg); color: var(--link); }
.pill.queued, .pill.fetching { color: var(--warn); }
.pill.ready { color: var(--accent); }
.pill.failed { color: #d93025; }
input.field { display: block; width: 100%; border: 1px solid var(--bg2); border-radius: 12px; padding: 13px 14px; font: inherit; background: var(--bg); color: var(--text); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Editor ---------- */
.stage { position: relative; width: min(100%, calc(58vh * 9 / 16)); aspect-ratio: 9 / 16; margin: 12px auto 0; background: #000; border-radius: var(--radius); overflow: hidden; --s: .3; }
.stage video { position: absolute; inset: 0; width: 100%; height: 100%; max-height: none; border-radius: 0; background: transparent; }
.stage .bgv { object-fit: cover; filter: blur(12px); transform: scale(1.1); }
.stage .ov { position: absolute; pointer-events: none; }
.stage .logo { height: auto; }
.stage .hook, .stage .caption, .stage .cta { left: 0; right: 0; text-align: center; font-family: "DejaVu Sans", Verdana, system-ui, sans-serif; font-weight: 700; }
.stage .hook span, .stage .caption span, .stage .cta span { display: block; width: fit-content; margin: 0 auto; white-space: pre; }
.stage .hook span { font-size: calc(var(--s) * 64px); line-height: calc(var(--s) * 96px); color: #000; }
.stage .hook span::before { content: none; }
.stage .hook span { background: rgba(255, 255, 255, .95); padding: 0 calc(var(--s) * 16px); box-decoration-break: clone; height: calc(var(--s) * 96px); display: flex; align-items: center; }
.stage .caption span { font-size: calc(var(--s) * 58px); line-height: calc(var(--s) * 76px); color: #fff; -webkit-text-stroke: calc(var(--s) * 10px) #000; paint-order: stroke fill; }
.stage .cta span { font-size: calc(var(--s) * 52px); line-height: 1.25; color: #000; background: #8ef06b; padding: calc(var(--s) * 22px); }
video.final { margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chips.tight { margin-top: 0; gap: 4px; }
.chip { border: 0; border-radius: 99px; padding: 8px 12px; font: inherit; font-size: 14px; background: var(--bg2); color: var(--text); }
.card .chip, .cap .chip { background: var(--bg2); }
.chip.on { background: var(--btn); color: var(--btn-text); }
.chips:not(.tight) .chip { background: var(--bg); }
.card .chips .chip { background: var(--bg2); }
.chips .chip.on { background: var(--btn); color: var(--btn-text); }
.cap { background: var(--bg); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.cap .row { margin-top: 6px; flex-wrap: wrap; }
select.field { margin-top: 8px; appearance: auto; }
input.field + select.field, input.field + input.field { margin-top: 8px; }

/* ---------- CapCut-style editor (always dark) ---------- */
body.ce-on { background: #000; overflow: hidden; overscroll-behavior: none; }
body.ce-on main { padding: 0; max-width: none; }
.ce {
  --ce-bg: #000; --ce-panel: #141414; --ce-panel2: #222; --ce-text: #fff; --ce-muted: #9a9a9a; --ce-accent: #ffffff;
  --ce-cap: #f5a524; --ce-hook: #8b5cf6; --ce-cta: #8ef06b; --ce-logo: #3fa7ff;
  position: fixed; inset: 0; height: var(--tg-viewport-stable-height, 100dvh); display: flex; flex-direction: column;
  background: var(--ce-bg); color: var(--ce-text); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.ce button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.ce-top { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; flex: none; }
.ce-top-mid { display: flex; flex-direction: column; align-items: center; font-size: 13px; font-weight: 600; }
.ce-saved { color: var(--ce-muted); font-size: 11px; font-weight: 400; min-height: 14px; }
.ce-icon { width: 36px; height: 36px; font-size: 20px; border-radius: 50%; }
.ce-icon:disabled { opacity: .3; }
.ce .ce-export { background: var(--ce-accent); color: #000; font-weight: 700; border-radius: 8px; padding: 7px 16px; }
.ce-export:disabled { opacity: .5; }
.ce-notice { margin: 0 12px 6px; padding: 8px 10px; border-radius: 8px; background: #3a2a00; color: #ffd37a; font-size: 13px; flex: none; }
.ce-preview { flex: 1 1 auto; min-height: 120px; display: flex; align-items: center; justify-content: center; padding: 4px 0; overflow: hidden; }
.ce-stage { height: 100%; width: auto; max-width: 100%; margin: 0; border-radius: 6px; }
.stage .ov.tapable { pointer-events: auto; cursor: pointer; }
.ce-playbar { flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 6px 12px; }
.ce-time { font-variant-numeric: tabular-nums; font-size: 13px; color: #ddd; }
.ce-play-btn { width: 40px; height: 40px; font-size: 20px; }
.ce-undo { justify-self: end; display: flex; gap: 4px; }

.ce-timeline { position: relative; flex: none; height: 178px; background: var(--ce-bg); border-top: 1px solid #111; }
.ce-scroll { position: absolute; inset: 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; touch-action: pan-x; }
.ce-scroll::-webkit-scrollbar { display: none; }
.ce-inner { position: relative; box-sizing: content-box; height: 100%; }
.ce-ruler { position: relative; height: 22px; }
.ce-tick { position: absolute; top: 4px; transform: translateX(-50%); font-size: 10px; color: var(--ce-muted); font-variant-numeric: tabular-nums; }
.ce-tick::after { content: ""; position: absolute; left: 50%; top: 14px; width: 1px; height: 4px; background: #555; }
.ce-track { position: relative; margin-bottom: 6px; }
.ce-vtrack { height: 52px; }
.ce-otrack, .ce-ctrack { height: 30px; }
.ce-ltrack { height: 18px; }
.ce-ltrack .ce-bar { height: 16px; font-size: 10px; }
.ce-clip { position: absolute; left: 0; top: 0; height: 52px; border-radius: 6px; background: #1d1d1d; }
.ce-clip.nothumbs { background: repeating-linear-gradient(90deg, #2a2a2a 0 28px, #222 28px 30px); }
.ce-frames { position: absolute; inset: 0; overflow: hidden; border-radius: 6px; }
.ce-frame { position: absolute; top: 0; height: 52px; background-repeat: no-repeat; }
.ce-len { position: absolute; left: 6px; top: 4px; font-size: 10px; background: rgba(0, 0, 0, .6); padding: 1px 5px; border-radius: 4px; pointer-events: none; }
.ce-clip.sel { outline: 2px solid #fff; }
.ce-handle { position: absolute; top: -2px; bottom: -2px; width: 18px; background: #fff; display: none; touch-action: none; z-index: 2; }
.ce-handle::after { content: ""; position: absolute; left: 7px; top: 50%; width: 4px; height: 16px; margin-top: -8px; border-radius: 2px; background: #000; }
.ce-handle.left { left: -18px; border-radius: 6px 0 0 6px; }
.ce-handle.right { right: -18px; border-radius: 0 6px 6px 0; }
.ce-clip.sel .ce-handle { display: block; }
.ce-bar { position: absolute; top: 0; height: 28px; border-radius: 5px; padding: 0 8px; display: flex; align-items: center; font-size: 12px; font-weight: 600; color: #000; overflow: hidden; white-space: nowrap; box-sizing: border-box; }
.ce-bar span { overflow: hidden; text-overflow: ellipsis; }
.ce-bar.hook { background: var(--ce-hook); color: #fff; }
.ce-bar.cap { background: var(--ce-cap); }
.ce-bar.cta { background: var(--ce-cta); }
.ce-bar.logo { background: var(--ce-logo); color: #fff; opacity: .85; }
.ce-bar.sel { outline: 2px solid #fff; z-index: 3; touch-action: none; overflow: visible; }
.ce-bar-handle { position: absolute; top: 0; bottom: 0; width: 16px; background: #fff; display: none; touch-action: none; }
.ce-bar-handle.left { left: -14px; border-radius: 5px 0 0 5px; }
.ce-bar-handle.right { right: -14px; border-radius: 0 5px 5px 0; }
.ce-bar.sel .ce-bar-handle { display: block; }
.ce-playhead { position: absolute; left: 50%; top: 18px; bottom: 6px; width: 2px; margin-left: -1px; background: #fff; border-radius: 1px; pointer-events: none; box-shadow: 0 0 4px rgba(0, 0, 0, .8); z-index: 4; }
.ce-playhead::before { content: ""; position: absolute; top: -4px; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: #fff; }

.ce-tools { flex: none; display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 8px 6px calc(10px + env(safe-area-inset-bottom)); background: var(--ce-panel); }
.ce-tools::-webkit-scrollbar { display: none; }
.ce .ce-tool { flex: 0 0 auto; min-width: 64px; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 6px; font-size: 11px; color: #eee; }
.ce-tool-i { font-size: 20px; line-height: 26px; height: 26px; }
.ce .ce-tool.danger { color: #ff6b6b; }

.ce-sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--ce-panel); border-radius: 14px 14px 0 0; padding: 0 14px calc(14px + env(safe-area-inset-bottom)); transform: translateY(105%); transition: transform .2s ease; z-index: 10; max-height: 60%; overflow-y: auto; box-shadow: 0 -6px 24px rgba(0, 0, 0, .6); }
.ce-sheet.open { transform: none; }
.ce-sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 0 8px; position: sticky; top: 0; background: var(--ce-panel); }
.ce .ce-done { width: 36px; height: 36px; border-radius: 50%; background: #fff; color: #000; font-weight: 700; }
.ce-sheet-body .muted { color: var(--ce-muted); }
.ce-info { margin: 8px 0; font-variant-numeric: tabular-nums; }
.ce-input { display: block; width: 100%; box-sizing: border-box; background: var(--ce-panel2); color: #fff; border: 1px solid #333; border-radius: 10px; padding: 12px; font: inherit; resize: none; user-select: text; -webkit-user-select: text; margin-top: 4px; }
.ce-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; }
.ce-opts.col { flex-direction: column; align-items: stretch; }
.ce .ce-opt { background: var(--ce-panel2); border-radius: 10px; padding: 10px 12px; text-align: left; }
.ce .ce-opt.on { background: #fff; color: #000; font-weight: 600; }
.ce .ce-opts.big .ce-opt { flex: 1; text-align: center; padding: 14px 8px; }
.ce-opt-i { display: block; font-size: 22px; }
.ce-logo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; aspect-ratio: 9 / 8; max-width: 260px; }
.ce-logo-grid .ce-opt { text-transform: capitalize; display: flex; align-items: flex-start; }
.ce-logo-grid .ce-opt:nth-child(2), .ce-logo-grid .ce-opt:nth-child(4) { justify-content: flex-end; }
.ce-logo-grid .ce-opt:nth-child(3), .ce-logo-grid .ce-opt:nth-child(4) { align-items: flex-end; }

/* ---------- Editor audio ---------- */
.ce-atrack { min-height: 26px; }
.ce-atrack .ce-bar { height: 24px; font-size: 11px; }
.ce-bar.aud { background-color: #0f766e; color: #fff; background-repeat: no-repeat; }
.ce-bar.aud span { background: rgba(0, 0, 0, .35); padding: 0 4px; border-radius: 3px; }
.ce-bar.missing { background-color: #7f1d1d; }
.ce .ce-orig { position: absolute; left: 4px; top: 24px; z-index: 5; width: 52px; height: 52px; border-radius: 8px; background: rgba(30, 30, 30, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 10px; color: #ddd; }
.ce-orig-i { font-size: 18px; line-height: 20px; }
.ce-timeline { transition: height .15s; }
.ce-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.ce .ce-tabs .ce-opt { flex: 1; text-align: center; padding: 8px; }
.ce-cat { margin: 12px 0 4px; font-size: 12px; color: var(--ce-muted); text-transform: uppercase; letter-spacing: .04em; }
.ce-snd { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #222; }
.ce .ce-snd-play { width: 36px; height: 36px; border-radius: 50%; background: var(--ce-panel2); flex: none; }
.ce-snd-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ce-snd-name b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ce .ce-snd-add { background: #fff; color: #000; border-radius: 8px; padding: 6px 12px; font-weight: 600; flex: none; }
.ce .ce-snd-add:disabled { background: #333; color: #888; }
.ce .ce-snd-del { width: 32px; height: 32px; flex: none; }
.ce-slider { display: block; margin-top: 12px; }
.ce-range { width: 100%; accent-color: #fff; margin-top: 6px; }
.ce .ce-rec { background: #dc2626; color: #fff; border-radius: 999px; padding: 12px 22px; font-weight: 700; }
.ce .ce-rec.on { background: #fff; color: #dc2626; }
.ce .ce-rec:disabled { opacity: .5; }

/* ---------- Review ---------- */
.review-video { margin: 10px auto; width: min(100%, 300px); aspect-ratio: 9 / 16; max-height: 60vh; }
textarea.field { display: block; width: 100%; box-sizing: border-box; border: 1px solid var(--bg2); border-radius: 12px; padding: 12px; font: inherit; background: var(--bg2); color: var(--text); resize: vertical; }
.review-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.review-btns .btn { margin-top: 8px; padding: 12px 6px; font-size: 14px; }
.btn.danger { color: #d93025; }
.pill.approved { color: var(--accent); }
.pill.changes_requested, .pill.rejected { color: #d93025; }

/* Draggable logo in the editor preview */
.stage .ov.logo { pointer-events: auto; cursor: grab; touch-action: none; user-select: none; -webkit-user-drag: none; }
.stage .ov.logo.sel { outline: 2px dashed #fff; outline-offset: 2px; }

/* ---------- Wallet ---------- */
.card.wallet { margin-top: 12px; background: linear-gradient(135deg, #0f3d2e, #14532d); color: #fff; }
.wallet-label { font-size: 14px; opacity: .85; }
.wallet-more { font-size: 13px; opacity: .8; }
.wallet-amount { font-size: 32px; font-weight: 800; margin: 4px 0 8px; letter-spacing: -.5px; }
.wallet-bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, .2); overflow: hidden; }
.wallet-bar > div { height: 100%; background: #8ef06b; border-radius: 3px; }
.wallet-note { font-size: 13px; margin-top: 8px; opacity: .9; }
.plus { color: var(--accent); }
