/* ── سنا كاميرا — design tokens ── */
:root {
  --bg: #0f172a;
  --bg-deep: #0a1120;
  --card: rgba(255, 255, 255, .05);
  --card-hover: rgba(255, 255, 255, .08);
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .16);
  --text: #ffffff;
  --muted: #8b93a7;
  --primary: #7c3aed;
  --primary-2: #6366f1;
  --accent: #0891b2;
  --accent-2: #22d3ee;
  --danger: #dc2626;
  --success: #34d399;
  --grad: linear-gradient(135deg, #7c3aed, #6366f1 55%, #0891b2);
  --r-sm: 10px;
  --r: 16px;
  --r-lg: 22px;
  --r-full: 999px;
  --sh: 0 8px 32px rgba(0, 0, 0, .42);
  --sh-lg: 0 18px 56px rgba(0, 0, 0, .55);
  --t: transform .18s ease, box-shadow .18s ease, background .18s ease, opacity .2s ease;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans Arabic", Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(ellipse 60% 46% at 50% -6%, rgba(124, 58, 237, .34), transparent 62%),
    radial-gradient(ellipse 46% 40% at 96% 8%, rgba(8, 145, 178, .26), transparent 66%);
}
i[data-lucide] { display: inline-flex; line-height: 0; }
i[data-lucide] svg { width: 18px; height: 18px; stroke-width: 1.75; }
button { font: inherit; color: inherit; cursor: pointer; }
::selection { background: rgba(124, 58, 237, .45); }
.hidden { display: none !important; }

/* ── Navbar ── */
.navbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem 1.4rem;
  background: rgba(10, 17, 32, .78);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .7rem; }
.brand-mark {
  display: grid; place-items: center; width: 40px; height: 40px;
  border-radius: 13px; background: var(--grad); color: #fff;
  box-shadow: 0 8px 24px rgba(124, 58, 237, .4);
}
.brand-mark i[data-lucide] svg { width: 21px; height: 21px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 1.02rem; font-weight: 700; letter-spacing: -.02em; }
.brand-text small { color: var(--muted); font-size: .74rem; }
.tools { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.tool {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .45rem .8rem; border-radius: var(--r-full);
  background: var(--card); border: 1px solid var(--line);
  color: var(--muted); font-size: .8rem; font-weight: 600;
  transition: var(--t); backdrop-filter: blur(10px);
}
.tool:hover { color: var(--text); background: var(--card-hover); transform: translateY(-2px); }
.tool.active { color: #fff; border-color: rgba(124, 58, 237, .6); background: rgba(124, 58, 237, .22); }
.tool.accent { color: #dbeafe; border-color: rgba(34, 211, 238, .34); background: rgba(8, 145, 178, .2); }
.tool.accent:hover { background: rgba(8, 145, 178, .34); }

/* ── Shell ── */
.shell {
  position: relative; z-index: 1;
  max-width: 1400px; margin: 0 auto;
  padding: 1.1rem 1.4rem 7.4rem;
  display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .85fr);
  gap: 1.1rem; align-items: start;
}
.stage { display: flex; flex-direction: column; gap: .6rem; }
.hint { color: var(--muted); font-size: .82rem; padding-inline: .3rem; }

/* ── Viewfinder ── */
.viewfinder {
  position: relative; width: 100%; aspect-ratio: 16 / 9;
  background: #05080f radial-gradient(circle at 50% 40%, #131c30, #05080f 70%);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  overflow: hidden; box-shadow: var(--sh-lg);
  transition: aspect-ratio .25s ease;
}
.viewfinder video {
  width: 100%; height: 100%; object-fit: cover; display: block;
  background: #05080f;
}
.viewfinder.mirrored video { transform: scaleX(-1); }
.layer { position: absolute; inset: 0; pointer-events: none; }
.tint { mix-blend-mode: soft-light; opacity: 0; transition: opacity .2s ease; background: transparent; }
.grain { opacity: 0; background-image: var(--noise); background-size: 190px 190px; mix-blend-mode: overlay; }
.vignette { opacity: 0; background: radial-gradient(ellipse at 50% 50%, transparent 42%, rgba(0,0,0,.85) 100%); }
.grid { opacity: 0; transition: opacity .2s; }
.grid.on { opacity: 1; }
.grid::before {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(rgba(255, 255, 255, .26) 0 0) 33.333% 0 / 1px 100% no-repeat,
    linear-gradient(rgba(255, 255, 255, .26) 0 0) 66.666% 0 / 1px 100% no-repeat,
    linear-gradient(rgba(255, 255, 255, .26) 0 0) 0 33.333% / 100% 1px no-repeat,
    linear-gradient(rgba(255, 255, 255, .26) 0 0) 0 66.666% / 100% 1px no-repeat;
}
.flash { background: #fff; opacity: 0; }
.flash.fire { animation: flashFire .42s ease-out; }
@keyframes flashFire { 0% { opacity: .95 } 100% { opacity: 0 } }
.countdown {
  position: absolute; inset: 0; display: none; place-items: center;
  font-size: clamp(4rem, 14vw, 8rem); font-weight: 700; color: #fff;
  text-shadow: 0 6px 40px rgba(0, 0, 0, .8); letter-spacing: -.04em;
}
.countdown.on { display: grid; }
.countdown span { animation: pop .9s ease-out; }
@keyframes pop { from { transform: scale(1.5); opacity: .2 } to { transform: none; opacity: 1 } }

/* ── HUD + status ── */
.hud { position: absolute; left: 0; right: 0; display: flex; gap: .45rem; padding: .85rem; pointer-events: none; }
.hud.top { top: 0; justify-content: flex-start; }
.hud.bottom { bottom: 0; justify-content: space-between; align-items: flex-end; }
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .32rem .7rem; border-radius: var(--r-full);
  background: rgba(5, 8, 15, .55); border: 1px solid var(--line);
  backdrop-filter: blur(10px); font-size: .74rem; font-weight: 600; color: #e6ebf5;
}
.badge i[data-lucide] svg { width: 14px; height: 14px; }
.badge b { font-weight: 700; letter-spacing: .01em; }
.badge.soft { background: rgba(5, 8, 15, .45); color: var(--muted); }
.badge.hi { border-color: rgba(34, 211, 238, .5); color: #cffafe; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: #ef4444; box-shadow: 0 0 10px #ef4444; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .25 } }
.cam-status {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: .8rem; text-align: center;
  padding: 1.5rem; background: rgba(5, 8, 15, .82); backdrop-filter: blur(6px);
}
.cam-status p { color: var(--muted); font-size: .88rem; max-width: 420px; }
.cam-status.error p { color: #fca5a5; }
.cam-status.gone { display: none; }
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 3px solid rgba(124, 58, 237, .25); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }

/* ── Cards / side panel ── */
.side { display: flex; flex-direction: column; gap: 1.1rem; }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r); backdrop-filter: blur(12px);
  box-shadow: var(--sh);
}
.card.pad { padding: 1rem 1.1rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .8rem; }
.card-head h2 { font-size: .92rem; font-weight: 700; display: flex; align-items: center; gap: .45rem; }
.count {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 .35rem;
  border-radius: var(--r-full); background: rgba(124, 58, 237, .25); color: #ddd6fe; font-size: .72rem;
}
.ghost {
  display: inline-flex; align-items: center; gap: .35rem;
  background: transparent; border: 1px solid var(--line-strong); color: var(--muted);
  border-radius: var(--r-full); padding: .35rem .7rem; font-size: .75rem; font-weight: 600; transition: var(--t);
}
.ghost:hover { color: var(--text); background: var(--card-hover); transform: translateY(-1px); }
.ghost.sm { padding: .28rem .6rem; font-size: .72rem; }
.ghost i[data-lucide] svg { width: 14px; height: 14px; }

/* ── Filter strip ── */
.strip {
  display: flex; gap: .7rem; overflow-x: auto; padding: .2rem .1rem .7rem;
  scroll-snap-type: x proximity; scrollbar-width: thin;
}
.strip::-webkit-scrollbar { height: 6px; }
.strip::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: 99px; }
.strip.compact { padding: .6rem .1rem; }
.fchip {
  flex: 0 0 auto; width: 84px; scroll-snap-align: center;
  background: transparent; border: none; display: flex; flex-direction: column; gap: .45rem;
  align-items: center; transition: var(--t);
}
.fchip .thumb {
  position: relative; width: 84px; height: 84px; border-radius: 14px; overflow: hidden;
  border: 2px solid var(--line-strong); background: linear-gradient(135deg, #1e293b, #0f172a);
  display: grid; place-items: center; color: rgba(255, 255, 255, .35);
}
.fchip .thumb img, .fchip .thumb canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.fchip .thumb::after {
  content: ""; position: absolute; inset: 0; border-radius: 12px;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, .35);
}
.fchip span { font-size: .68rem; font-weight: 600; color: var(--muted); text-align: center; line-height: 1.3; }
.fchip:hover .thumb { transform: translateY(-3px); }
.fchip.on .thumb { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(124, 58, 237, .3), 0 12px 30px rgba(124, 58, 237, .3); }
.fchip.on span { color: #fff; }

/* ── Sliders ── */
.sliders { display: flex; flex-direction: column; gap: .75rem; }
.srow { display: grid; grid-template-columns: 1fr auto; gap: .3rem .5rem; }
.srow label { display: flex; align-items: center; gap: .35rem; font-size: .76rem; font-weight: 600; color: var(--muted); text-transform: none; letter-spacing: 0; }
.srow i[data-lucide] svg { width: 14px; height: 14px; }
.srow output { font-size: .74rem; font-weight: 700; color: #c7d2fe; font-family: Inter, monospace; }
input[type="range"] {
  grid-column: 1 / -1; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 99px;
  background: linear-gradient(90deg, var(--primary) var(--p, 50%), rgba(255, 255, 255, .12) var(--p, 50%));
  outline: none; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; border: 3px solid var(--primary); box-shadow: 0 2px 10px rgba(0, 0, 0, .5);
}
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border: 3px solid var(--primary); border-radius: 50%; background: #fff; }

/* ── Gallery ── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: .5rem; }
.gallery .empty {
  grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; gap: .4rem;
  padding: 1.4rem .6rem; color: var(--muted); font-size: .78rem; text-align: center;
  border: 1px dashed var(--line-strong); border-radius: var(--r-sm);
}
.gallery .empty i[data-lucide] svg { width: 26px; height: 26px; }
.gitem {
  position: relative; aspect-ratio: 1; border-radius: var(--r-sm); overflow: hidden;
  border: 1px solid var(--line); cursor: pointer; transition: var(--t); background: #0b1220;
}
.gitem img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gitem:hover { transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 10px 26px rgba(0, 0, 0, .5); }
.gitem b {
  position: absolute; inset-inline-start: 4px; bottom: 4px; padding: 1px 5px; border-radius: 6px;
  background: rgba(5, 8, 15, .7); font-size: .6rem; font-weight: 600; color: #e6ebf5; backdrop-filter: blur(4px);
}

/* ── Shutter bar ── */
.shutter-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem max(1.2rem, env(safe-area-inset-left)) calc(.8rem + env(safe-area-inset-bottom));
  background: rgba(10, 17, 32, .86); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.ratios { display: flex; gap: .35rem; flex-wrap: wrap; }
.ratio {
  padding: .32rem .72rem; border-radius: var(--r-full); background: rgba(255, 255, 255, .05);
  border: 1px solid var(--line); color: var(--muted); font-size: .74rem; font-weight: 600; transition: var(--t);
}
.ratio:hover { color: #fff; }
.ratio.on { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 6px 20px rgba(124, 58, 237, .38); }
.shutter {
  position: relative; width: 68px; height: 68px; border-radius: 50%; flex: 0 0 auto;
  background: transparent; border: 3px solid rgba(255, 255, 255, .85); display: grid; place-items: center;
  transition: var(--t);
}
.shutter span { width: 52px; height: 52px; border-radius: 50%; background: #fff; transition: var(--t); }
.shutter:hover { transform: scale(1.05); }
.shutter:hover span { background: var(--accent-2); }
.shutter:active span { transform: scale(.88); }
.shutter:disabled { opacity: .4; cursor: not-allowed; }
.shutter.rec span { background: var(--danger); width: 30px; height: 30px; border-radius: 8px; }
.last-shot {
  width: 52px; height: 52px; border-radius: 13px; overflow: hidden; padding: 0; flex: 0 0 auto;
  border: 1px solid var(--line-strong); background: linear-gradient(135deg, #1e293b, #0f172a); transition: var(--t);
}
.last-shot img { width: 100%; height: 100%; object-fit: cover; display: none; }
.last-shot img.on { display: block; }
.last-shot:hover { transform: translateY(-2px); border-color: var(--accent-2); }

/* ── Modals ── */
.overlay {
  position: fixed; inset: 0; z-index: 60; padding: 1rem;
  background: rgba(3, 6, 12, .72); backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  animation: fadeUp .22s ease;
}
.modal {
  width: 100%; max-width: 420px; padding: 1.2rem;
  background: linear-gradient(180deg, #131c30, #0c1424);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--sh-lg);
  max-height: 92dvh; overflow: auto;
}
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.modal-head h3 { font-size: 1rem; font-weight: 700; }
.modal img { width: 100%; border-radius: var(--r); display: block; background: #05080f; max-height: 62dvh; object-fit: contain; }
.modal-foot { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }
.ed-stage { border-radius: var(--r); overflow: hidden; background: #05080f; display: grid; place-items: center; }
.ed-stage img { max-height: 52dvh; width: auto; }
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); color: var(--muted); transition: var(--t);
}
.icon-btn:hover { color: #fff; background: var(--card-hover); }
.btn {
  display: inline-flex; align-items: center; gap: .4rem; padding: .6rem 1.15rem;
  border-radius: var(--r-full); border: none; font-size: .84rem; font-weight: 600; transition: var(--t);
}
.btn i[data-lucide] svg { width: 16px; height: 16px; }
.btn.primary { background: var(--grad); color: #fff; box-shadow: 0 8px 26px rgba(124, 58, 237, .36); }
.btn.primary:hover { transform: translateY(-2px); box-shadow: 0 12px 34px rgba(124, 58, 237, .5); }
.btn.ghost { background: transparent; border: 1px solid var(--line-strong); color: var(--muted); }
.btn.ghost:hover { color: #fff; background: var(--card-hover); }
.btn.danger { background: rgba(220, 38, 38, .16); border: 1px solid rgba(220, 38, 38, .42); color: #fca5a5; }
.btn.danger:hover { background: rgba(220, 38, 38, .3); }

/* ── Toasts ── */
.toasts { position: fixed; inset-inline-end: 1.2rem; bottom: 6.4rem; z-index: 80; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  display: flex; align-items: center; gap: .5rem; padding: .6rem 1rem; border-radius: var(--r-sm);
  background: rgba(13, 20, 36, .95); border: 1px solid var(--line-strong); box-shadow: var(--sh-lg);
  font-size: .82rem; font-weight: 600; animation: fadeUp .28s ease;
}
.toast.ok { border-color: rgba(52, 211, 153, .45); color: #a7f3d0; }
.toast.err { border-color: rgba(248, 113, 113, .45); color: #fecaca; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }

/* ── Responsive ── */
@media (max-width: 1080px) {
  .shell { grid-template-columns: 1fr; }
  .side { order: 2; }
}
@media (max-width: 640px) {
  body { font-size: 14px; }
  .navbar { padding: .6rem .8rem; flex-wrap: wrap; }
  .tool span { display: none; }
  .tool { padding: .5rem; }
  .brand-text small { display: none; }
  .shell { padding: .8rem .8rem 8rem; }
  .viewfinder { border-radius: var(--r); }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); }
  .fchip, .fchip .thumb { width: 72px; }
  .fchip .thumb { height: 72px; }
  .shutter-bar { padding: .6rem .7rem calc(.6rem + env(safe-area-inset-bottom)); }
  .ratios { max-width: 40%; overflow-x: auto; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ── محرّر الصور من الجهاز ── */
.ed-stage { position: relative; }
.ed-stage img { position: relative; z-index: 1; }
.ed-stage .ed-tint, .ed-stage .ed-vig { z-index: 2; pointer-events: none; }

/* أيقونة غير محمّلة (انقطاعCDN) → لا تترك فراغاً، النص العربي يكفي */
i[data-lucide]:empty { display: none; }
