:root {
  --navy: #0a0f1e;
  --navy-2: #111a30;
  --navy-3: #18233f;
  --gold: #c9a84c;
  --gold-soft: #e6cd86;
  --white: #f5f3ea;
  --muted: #9aa6c2;
  --line: rgba(201, 168, 76, 0.18);
  --danger: #e0635a;
  --ok: #6bbf7b;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-family: "Reem Kufi", "Segoe UI", system-ui, sans-serif;
}

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

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(201,168,76,0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(64,120,200,0.10), transparent 60%),
    var(--navy);
  color: var(--white);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold-soft); }

/* ---------- Header ---------- */
.site-header { text-align: center; padding: 32px 20px 6px; }
.brand { display: inline-flex; align-items: center; gap: 14px; }
.brand-mark { font-size: 46px; color: var(--gold); text-shadow: 0 0 24px rgba(201,168,76,0.45); }
.brand-text { text-align: right; line-height: 1.1; }
.brand-text h1 {
  margin: 0; font-size: 36px; font-weight: 700; letter-spacing: 0.5px;
  font-family: "Aref Ruqaa", "Amiri", serif;
  background: linear-gradient(180deg, var(--gold-soft), var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand-sub { font-size: 13px; letter-spacing: 2px; color: var(--muted); }
.tagline { color: var(--muted); margin: 14px 0 0; font-size: 15px; }

/* ---------- Layout ---------- */
.layout {
  max-width: 1180px; margin: 26px auto 0; padding: 0 20px 40px;
  display: grid; grid-template-columns: 360px 1fr; gap: 22px; align-items: start;
}
@media (max-width: 920px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: linear-gradient(180deg, var(--navy-2), var(--navy));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px;
}
.panel-title { margin: 0 0 18px; font-size: 18px; color: var(--gold-soft); font-weight: 600; }

/* ---------- Fields ---------- */
.field { margin-bottom: 18px; }
label { display: block; margin-bottom: 7px; font-size: 14px; color: var(--muted); }
select {
  width: 100%; padding: 12px 14px; background: var(--navy-3);
  border: 1px solid var(--line); border-radius: 12px; color: var(--white);
  font-family: inherit; font-size: 15px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
select:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,168,76,0.18); }
select:disabled { opacity: .6; }
.hint { margin: 8px 2px 0; font-size: 13px; color: var(--muted); }
.hint.center { text-align: center; }

/* ---------- Segmented (aspect ratio) ---------- */
.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.seg-btn {
  border: 1px solid var(--line); background: var(--navy-3); color: var(--muted);
  border-radius: 12px; padding: 10px 4px; cursor: pointer; text-align: center;
  font-family: inherit; transition: all .15s; line-height: 1.25;
}
.seg-btn .seg-ratio { display: block; font-size: 15px; font-weight: 700; color: var(--white); }
.seg-btn .seg-tag { display: block; font-size: 10px; margin-top: 3px; }
.seg-btn:hover { border-color: var(--gold); }
.seg-btn.active { background: rgba(201,168,76,0.14); border-color: var(--gold); color: var(--gold-soft); }
.seg-btn.active .seg-ratio { color: var(--gold-soft); }

/* ---------- Background grid ---------- */
.bg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.bg-chip {
  position: relative; aspect-ratio: 1 / 1; border-radius: 12px; border: 2px solid transparent;
  cursor: pointer; overflow: hidden; display: flex; align-items: flex-end; justify-content: center;
  padding: 6px; color: var(--white); font-size: 11px; text-align: center;
  background: var(--navy-3); background-size: cover; background-position: center;
  transition: transform .15s, border-color .15s;
}
.bg-chip span { position: relative; z-index: 2; text-shadow: 0 1px 4px rgba(0,0,0,0.9); line-height: 1.2; }
.bg-chip::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 35%, rgba(0,0,0,0.75)); z-index: 1; }
.bg-chip.random { background: linear-gradient(135deg, #1b2747, #2a1640); font-size: 13px; }
.bg-chip.random::after { display: none; }
.bg-chip:hover { transform: translateY(-2px); }
.bg-chip.active { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(201,168,76,0.25); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 14px 18px; border: 1px solid transparent; border-radius: 12px;
  font-family: inherit; font-size: 16px; font-weight: 600; cursor: pointer;
  transition: transform .12s, opacity .15s, background .2s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: #20180a; font-size: 17px; }
.btn-gold { background: linear-gradient(180deg, #d8534b, #b8332b); color: #fff; }
.btn-ghost { background: var(--navy-3); border-color: var(--line); color: var(--white); width: auto; flex: 1; }

/* ---------- Stage ---------- */
.stage-center { display: flex; justify-content: center; }
.canvas-wrap {
  position: relative; aspect-ratio: 9 / 16; width: min(100%, calc(70vh * 9 / 16));
  border-radius: 14px; overflow: hidden; background: #000; border: 1px solid var(--line);
  box-shadow: var(--shadow); transition: width .2s;
}
#stage-canvas { width: 100%; height: 100%; display: block; }
#bg-video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; left: -9999px; }
.stage-overlay, .stage-loader {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; background: rgba(10,15,30,0.72); color: var(--muted);
}
.overlay-inner .overlay-icon { display: block; font-size: 40px; color: var(--gold); margin-bottom: 10px; }
.stage-loader { flex-direction: column; gap: 14px; backdrop-filter: blur(2px); }
.hidden { display: none !important; }

.spinner {
  width: 42px; height: 42px; border: 3px solid rgba(201,168,76,0.25);
  border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.meta-line { text-align: center; margin-top: 14px; font-size: 14px; color: var(--gold-soft); min-height: 20px; }
.transport { display: flex; gap: 10px; margin-top: 12px; }
.rec-status { margin-top: 12px; min-height: 20px; font-size: 14px; color: var(--muted); text-align: center; }
.rec-status.recording { color: var(--danger); font-weight: 600; }
.rec-status.done { color: var(--ok); }

.download-link {
  display: block; margin-top: 12px; text-align: center; padding: 13px; border-radius: 12px;
  background: rgba(107,191,123,0.12); border: 1px solid rgba(107,191,123,0.4);
  color: var(--ok); text-decoration: none; font-weight: 600;
}

/* ---------- Footer ---------- */
.site-footer { text-align: center; padding: 18px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

/* ---------- Toasts ---------- */
#toast-host {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%); z-index: 1000;
  display: flex; flex-direction: column; gap: 10px; width: min(420px, 92vw);
}
.toast {
  padding: 13px 16px; border-radius: 12px; background: var(--navy-3);
  border: 1px solid var(--line); box-shadow: var(--shadow); font-size: 14px; animation: drop .25s ease;
}
.toast.error { border-color: rgba(224,99,90,0.5); color: #ffb4ad; }
.toast.ok { border-color: rgba(107,191,123,0.5); color: #b6e6c0; }
@keyframes drop { from { opacity: 0; transform: translateY(-10px); } }
