@font-face { font-family: 'DIN Next LT Arabic'; src: url('/static/fonts/DINNextLTArabic-Bold.ttf') format('truetype'); font-weight: 600 900; font-display: block; }
@font-face { font-family: 'DIN Next LT Arabic'; src: url('/static/fonts/DINNextLTArabic-Light.ttf') format('truetype'); font-weight: 300 500; font-display: block; }
@font-face { font-family: 'DIN Next LT Arabic'; src: url('/static/fonts/DINNextLTArabic-UltraLight.ttf') format('truetype'); font-weight: 200; font-display: block; }
@font-face { font-family: 'Tajawal'; src: url('/static/fonts/Tajawal-Medium.ttf') format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('/static/fonts/Tajawal-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('/static/fonts/Tajawal-ExtraBold.ttf') format('truetype'); font-weight: 800; font-display: swap; }

:root {
  --red: #8f0e0e;
  --red-2: #b31414;
  --bg: #0f0f12;
  --card: #17171c;
  --line: rgba(255,255,255,.08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }
html, body { font-family: 'DIN Next LT Arabic', 'Tajawal', system-ui, -apple-system, 'Segoe UI', sans-serif; background: var(--bg); overscroll-behavior-y: none; }
body { min-height: 100dvh; }

.app-shell { max-width: 560px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.app-header { position: relative; z-index: 30; display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px; background: rgba(15,15,18,.85); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line); }
.app-main { padding: 12px 12px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; }

/* Preview */
.preview-section { display: flex; justify-content: center; }
.preview-wrap { position: relative; width: 100%; max-height: 62vh; margin: 0 auto; background: #000; border-radius: 16px; overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,.6), 0 0 0 1px var(--line); }
.preview-wrap.aspect-\[9\/16\] { aspect-ratio: 9/16; width: min(100%, calc(62vh * 9 / 16)); }
.preview-wrap.aspect-\[16\/9\] { aspect-ratio: 16/9; width: 100%; max-height: none; }
.preview-canvas { width: 100%; height: 100%; display: block; }
.preview-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff; text-align: center;
  background: radial-gradient(ellipse at 50% 30%, #2a1010 0%, #0d0d10 70%); }
.preview-controls { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 10px 10px; direction: ltr; flex-wrap: nowrap;
  background: linear-gradient(to top, rgba(0,0,0,.75), transparent); }
.ctrl-btn { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.15); color: #fff; display: grid; place-items: center; flex: none; }
.ctrl-btn:active { background: rgba(255,255,255,.3); }
.seek { flex: 1; accent-color: var(--red-2); height: 4px; direction: ltr; }
.time-label { font-size: 10px; color: rgba(255,255,255,.85); font-variant-numeric: tabular-nums; direction: ltr; white-space: nowrap; flex: none; }
.seek { min-width: 40px; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.card-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.step { width: 24px; height: 24px; border-radius: 8px; background: var(--red); color: #fff; display: grid; place-items: center; font-size: 13px; font-weight: 800; }

.template-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tpl-btn { border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 4px; color: #ddd; background: #1d1d23; transition: .15s; }
.tpl-btn i { font-size: 20px; color: #bbb; }
.tpl-btn span { font-size: 12px; font-weight: 700; text-align: center; line-height: 1.2; }
.tpl-btn small { font-size: 10px; color: #888; direction: ltr; }
.tpl-btn.active { border-color: var(--red-2); background: linear-gradient(180deg, #3a1010, #22101000); color: #fff; }
.tpl-btn.active i { color: #ff5a5a; }

.video-drop { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 20px 12px; border: 1.5px dashed rgba(255,255,255,.22); border-radius: 12px; text-align: center; cursor: pointer; background: #1d1d23; }
.video-drop:active { background: #26262e; }
.video-drop.has-video { border-style: solid; border-color: #2f8f4a; background: #122018; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.label { font-size: 13px; color: #ddd; display: flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; background: #101014; border-radius: 10px; padding: 3px; gap: 3px; }
.seg-3 { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
.seg-btn { padding: 8px 10px; border-radius: 8px; font-size: 12px; font-weight: 700; color: #aaa; white-space: nowrap; }
.seg-btn.active { background: var(--red); color: #fff; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.field .opt { font-size: 10px; color: #777; font-weight: 400; direction: ltr; margin-inline-start: auto; font-family: monospace; }
.field input, .field textarea { width: 100%; background: #101014; border: 1.5px solid var(--line); border-radius: 10px; padding: 12px 12px; font-size: 16px; color: #fff; font-family: inherit; outline: none; resize: none; }
.field input:focus, .field textarea:focus { border-color: var(--red-2); }
.field input::placeholder, .field textarea::placeholder { color: #666; }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #333; border-radius: 28px; transition: .2s; }
.switch .slider::before { content: ''; position: absolute; width: 22px; height: 22px; top: 3px; right: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--red-2); }
.switch input:checked + .slider::before { transform: translateX(-20px); }

.vol-row { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 8px; }
.vol-row input { accent-color: var(--red-2); direction: ltr; }
.vol-row .val { font-size: 12px; color: #bbb; text-align: left; direction: ltr; font-variant-numeric: tabular-nums; }
.vol-row.disabled { opacity: .35; pointer-events: none; }

.btn-primary { width: 100%; padding: 14px; border-radius: 12px; background: linear-gradient(180deg, #c21818, #8f0e0e); color: #fff; font-weight: 800; font-size: 16px; display: flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 6px 20px rgba(180,20,20,.35); }
.btn-primary:disabled { opacity: .4; box-shadow: none; }
.btn-primary:not(:disabled):active { transform: scale(.98); }
.btn-secondary { width: 100%; padding: 14px; border-radius: 12px; background: #2a2a33; color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-ghost { padding: 8px 12px; border-radius: 10px; color: #ccc; font-size: 13px; background: rgba(255,255,255,.06); }
.export-card { }
/* Fixed bottom action bar (mobile) */
.action-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; padding: 10px 12px calc(10px + var(--safe-b)); background: rgba(15,15,18,.92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.action-bar .btn-primary { flex: 1; padding: 13px; font-size: 15px; }
.action-bar .btn-ghost { padding: 13px 14px; font-size: 14px; }
.app-main { padding-bottom: calc(92px + var(--safe-b)); }
.preview-section { position: sticky; top: 0; z-index: 15; background: var(--bg); padding: 8px 0 6px; margin: -12px -12px 0; padding-left: 12px; padding-right: 12px; }
.preview-wrap { max-height: 44vh; }
.preview-wrap.aspect-\[9\/16\] { width: min(100%, calc(44vh * 9 / 16)); }
.preview-wrap.aspect-\[16\/9\] { max-height: none; }
.progress { position: fixed; left: 12px; right: 12px; bottom: calc(70px + var(--safe-b)); z-index: 26; background: #1d1d23; border: 1px solid var(--line); border-radius: 14px; padding: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.quality-row { display: flex; align-items: center; gap: 8px; }
.quality-row .seg-btn { padding: 8px 10px; }

.progress-bar { height: 10px; background: #101014; border-radius: 10px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, #ff4d4d, #b31414); transition: width .2s; }
.result-video { width: 100%; max-height: 50vh; border-radius: 10px; background: #000; }

.history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item { text-align: right; background: #101014; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; color: #ddd; }
.history-item b { color: #fff; }
.history-item small { color: #888; display: block; margin-top: 2px; }

.toast { position: fixed; bottom: calc(84px + var(--safe-b)); left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.5); max-width: 90vw; text-align: center; }
.toast.error { background: #7a1212; }
.toast.ok { background: #1b5e2e; }
.compat { position: fixed; top: calc(60px + var(--safe-t)); left: 12px; right: 12px; background: #4a3000; color: #ffe2a8; padding: 10px 14px; border-radius: 10px; font-size: 12px; z-index: 40; line-height: 1.6; }

@media (min-width: 640px) {
  .app-shell { max-width: 1000px; }
  .app-main { display: grid; grid-template-columns: 1fr 1fr; align-items: start; padding-bottom: 24px; }
  .preview-section { grid-row: 1 / span 8; position: sticky; top: 12px; margin: 0; padding: 0; background: transparent; }
  .preview-wrap { max-height: 80vh; }
  .preview-wrap.aspect-\[9\/16\] { width: min(100%, calc(80vh * 9 / 16)); }
  .action-bar { position: static; background: transparent; border: 0; padding: 0; backdrop-filter: none; }
  .progress { position: static; box-shadow: none; }
  footer { grid-column: 1 / -1; }
}

/* Crop */
.crop-panel { display: flex; flex-direction: column; gap: 10px; }
.hint { font-size: 11px; color: #9a9a9a; line-height: 1.6; display: flex; gap: 6px; align-items: flex-start; }
.preview-canvas { touch-action: none; cursor: grab; }
.preview-canvas.dragging { cursor: grabbing; }
.crop-hint { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 6px 10px; border-radius: 20px; pointer-events: none; white-space: nowrap; backdrop-filter: blur(6px); }
.ctrl-btn.active-music { color: #ff8080; }
