*,*::before,*::after{ box-sizing:border-box; }

:root{
  --bg:#0c0d0f;
  --bg-2:#121316;
  --surface:#1a1c20;
  --surface-2:#22252b;
  --line:rgba(255,255,255,.075);
  --line-2:rgba(255,255,255,.15);
  --text:#f3f0ea;
  --muted:#a0a0a8;
  --muted-2:#70717a;
  --accent:#e7bd8a;
  --accent-2:#f5d6ac;
  --accent-ink:#191307;
  --dock-h: clamp(220px, 42vh, 400px);
  --noise: none;
}

html,body{ height:100%; }

body{
  margin:0;
  background:
    radial-gradient(120% 70% at 50% -14%, #1d1c1e 0%, #0c0d0f 62%) fixed,
    var(--bg);
  color:var(--text);
  font-family:'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size:15px;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
  overflow:hidden;
  -webkit-tap-highlight-color:transparent;
}

button, input{ font-family:inherit; }
button{ -webkit-user-select:none; user-select:none; cursor:pointer; }
button:disabled{ cursor:default; }
[hidden]{ display:none !important; }
img{ -webkit-user-drag:none; }

:focus-visible{ outline:2px solid var(--accent); outline-offset:2px; }

/* ---------- layout ---------- */
.app{
  height:100dvh;
  display:flex;
  flex-direction:column;
  overflow:hidden;
}

.topbar{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:9px 14px;
  border-bottom:1px solid var(--line);
  background:rgba(12,13,15,.78);
  backdrop-filter:blur(16px);
  -webkit-backdrop-filter:blur(16px);
  z-index:6;
}
.brand{ display:flex; align-items:center; gap:9px; }
.brand-mark{
  display:grid; place-items:center;
  width:38px; height:38px;
  flex:0 0 auto;
  border-radius:50%;
  background:radial-gradient(circle at 32% 26%, #2b2c32, #0d0e11 74%);
  box-shadow:0 6px 18px rgba(231,189,138,.18), inset 0 0 0 1px rgba(231,189,138,.42);
}
.brand-mark svg{ width:25px; height:25px; display:block; }
.brand-text{ font-weight:600; font-size:16px; letter-spacing:.2px; }
.topbar-actions{ display:flex; align-items:center; gap:8px; }

/* ---------- buttons ---------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
  height:40px; padding:0 14px;
  border-radius:12px;
  border:1px solid transparent;
  background:transparent;
  color:var(--text);
  font-size:14px; font-weight:500;
  transition:background .16s ease, color .16s ease, border-color .16s ease, transform .12s ease, box-shadow .16s ease;
}
.btn svg{ width:18px; height:18px; flex:0 0 auto; }
.btn:active{ transform:scale(.97); }
.btn-primary{
  background:linear-gradient(150deg, var(--accent-2), #dfae74);
  color:var(--accent-ink);
  font-weight:600;
  box-shadow:0 8px 22px rgba(231,189,138,.18);
}
.btn-primary:hover{ box-shadow:0 10px 26px rgba(231,189,138,.28); }
.btn-primary:disabled{
  background:var(--surface-2);
  color:var(--muted-2);
  box-shadow:none;
  transform:none;
}
.btn-ghost{
  background:var(--surface);
  border-color:var(--line);
  color:var(--text);
}
.btn-ghost:hover{ background:var(--surface-2); border-color:var(--line-2); }
.btn-lg{ height:48px; padding:0 22px; font-size:15px; border-radius:14px; }

.icon-btn{
  display:grid; place-items:center;
  width:44px; height:44px;
  flex:0 0 auto;
  border-radius:13px;
  background:var(--surface);
  border:1px solid var(--line);
  color:var(--text);
  transition:background .16s ease, color .16s ease, border-color .16s ease, transform .12s ease;
}
.icon-btn svg{ width:20px; height:20px; }
.icon-btn:hover{ background:var(--surface-2); border-color:var(--line-2); }
.icon-btn:active{ transform:scale(.94); }
.icon-btn.star.is-on{ color:var(--accent); border-color:rgba(231,189,138,.45); }
.icon-btn.star.is-on svg path{ fill:var(--accent); }
.icon-btn:disabled{ opacity:.4; }

/* ---------- stage ---------- */
.stage{
  flex:1 1 auto;
  min-height:0;
  display:flex;
  flex-direction:column;
}
.photo-area{
  flex:1 1 auto;
  min-height:0;
  position:relative;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:14px;
}
.photo-area.dragging::after{
  content:'أفلت الصورة هنا';
  position:absolute; inset:8px;
  display:grid; place-items:center;
  border:2px dashed var(--accent);
  border-radius:20px;
  background:rgba(231,189,138,.07);
  color:var(--accent);
  font-weight:600; font-size:15px;
  pointer-events:none;
}

.frame{
  position:relative;
  isolation:isolate;
  border-radius:14px;
  overflow:hidden;
  background:#000;
  box-shadow:0 24px 60px rgba(0,0,0,.62), 0 0 0 1px rgba(255,255,255,.06);
}
.frame img{
  display:block;
  width:100%; height:100%;
  object-fit:cover;
}
.layer{
  position:absolute;
  inset:0;
  pointer-events:none;
  border-radius:inherit;
}
.grain{
  background-image:var(--noise);
  background-size:96px 96px;
  background-repeat:repeat;
  mix-blend-mode:overlay;
}

/* ---------- empty state ---------- */
.empty{
  display:flex;
  flex-direction:column;
  align-items:center;
  text-align:center;
  gap:12px;
  padding:20px;
  max-width:430px;
}
.empty-mark{
  font-size:52px;
  font-weight:700;
  line-height:1;
  letter-spacing:-1.5px;
  background:linear-gradient(150deg, #f7dcb8, #c9985f);
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
}
.empty h1{
  margin:0;
  font-size:22px;
  font-weight:600;
  letter-spacing:-.2px;
}
.empty p{
  margin:0;
  font-size:14px;
  line-height:1.75;
  color:var(--muted);
}
.empty-actions{
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  gap:10px;
  margin-top:8px;
}

/* ---------- stage bar ---------- */
.stage-bar{
  flex:0 0 auto;
  display:flex;
  flex-direction:column;
  gap:7px;
  padding:8px 14px 11px;
  border-top:1px solid var(--line);
  background:rgba(18,19,22,.92);
  backdrop-filter:blur(14px);
  -webkit-backdrop-filter:blur(14px);
}
.bar-row{ display:flex; align-items:center; gap:10px; }
.cur-name{
  flex:1 1 auto;
  min-width:0;
  font-size:14px;
  font-weight:500;
  color:var(--text);
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}
.bar-slider{ display:flex; align-items:center; gap:10px; }
.bar-label{ font-size:12px; color:var(--muted-2); flex:0 0 auto; }
.bar-pct{
  font-size:12px;
  font-weight:500;
  color:var(--accent);
  min-width:38px;
  text-align:left;
  font-variant-numeric:tabular-nums;
  flex:0 0 auto;
}

input[type=range]{
  -webkit-appearance:none;
  appearance:none;
  flex:1 1 auto;
  min-width:60px;
  height:26px;
  background:transparent;
  direction:ltr;
  cursor:pointer;
}
input[type=range]::-webkit-slider-runnable-track{
  height:4px;
  border-radius:99px;
  background:linear-gradient(to right, var(--accent) 0%, var(--accent) var(--pct,100%), rgba(255,255,255,.13) var(--pct,100%), rgba(255,255,255,.13) 100%);
}
input[type=range]::-webkit-slider-thumb{
  -webkit-appearance:none;
  appearance:none;
  width:18px; height:18px;
  margin-top:-7px;
  border-radius:50%;
  background:#fff;
  border:3px solid var(--accent);
  box-shadow:0 2px 8px rgba(0,0,0,.55);
}
input[type=range]::-moz-range-track{
  height:4px; border-radius:99px;
  background:rgba(255,255,255,.13);
}
input[type=range]::-moz-range-progress{
  height:4px; border-radius:99px;
  background:var(--accent);
}
input[type=range]::-moz-range-thumb{
  width:13px; height:13px;
  border-radius:50%;
  background:#fff;
  border:3px solid var(--accent);
}

/* ---------- dock ---------- */
.dock{
  flex:0 0 auto;
  height:var(--dock-h);
  display:flex;
  flex-direction:column;
  min-height:0;
  background:var(--bg-2);
  border-top:1px solid var(--line);
  border-radius:20px 20px 0 0;
  box-shadow:0 -18px 40px rgba(0,0,0,.45);
}
.dock-grip{
  width:38px; height:4px;
  border-radius:99px;
  background:rgba(255,255,255,.14);
  margin:8px auto 0;
  flex:0 0 auto;
}
.dock-top{
  display:flex;
  gap:10px;
  padding:10px 14px 8px;
  flex:0 0 auto;
}
.search{
  flex:1 1 auto;
  min-width:0;
  display:flex;
  align-items:center;
  gap:9px;
  height:44px;
  padding:0 13px;
  border-radius:13px;
  background:var(--surface);
  border:1px solid var(--line);
}
.search svg{ width:17px; height:17px; color:var(--muted-2); flex:0 0 auto; }
.search input{
  flex:1 1 auto;
  min-width:0;
  background:transparent;
  border:0;
  outline:0;
  color:var(--text);
  font-size:14px;
  height:100%;
}
.search input::placeholder{ color:var(--muted-2); }
.search input::-webkit-search-cancel-button{ -webkit-appearance:none; }

.chips{
  display:flex;
  gap:8px;
  overflow-x:auto;
  padding:2px 14px 10px;
  flex:0 0 auto;
  scrollbar-width:none;
}
.chips::-webkit-scrollbar{ display:none; }
.chip{
  flex:0 0 auto;
  display:inline-flex;
  align-items:center;
  gap:6px;
  height:34px;
  padding:0 14px;
  border-radius:99px;
  background:var(--surface);
  border:1px solid var(--line);
  color:var(--muted);
  font-size:13px;
  font-weight:500;
  transition:background .16s ease, color .16s ease, border-color .16s ease;
}
.chip:hover{ background:var(--surface-2); color:var(--text); }
.chip.is-active{
  background:var(--accent);
  border-color:var(--accent);
  color:var(--accent-ink);
  font-weight:600;
}
.chip-count{
  font-size:11px;
  opacity:.62;
  font-variant-numeric:tabular-nums;
}

.grid-wrap{
  flex:1 1 auto;
  min-height:0;
  overflow-y:auto;
  overscroll-behavior:contain;
  -webkit-overflow-scrolling:touch;
  padding:0 12px 18px;
  scrollbar-width:thin;
  scrollbar-color:rgba(255,255,255,.18) transparent;
}
.grid-wrap::-webkit-scrollbar{ width:6px; }
.grid-wrap::-webkit-scrollbar-thumb{ background:rgba(255,255,255,.16); border-radius:99px; }
.grid-wrap::-webkit-scrollbar-track{ background:transparent; }

.grid{
  display:grid;
  grid-template-columns:repeat(3, minmax(0,1fr));
  gap:12px 8px;
}
@media (min-width:520px){
  .grid{ grid-template-columns:repeat(4, minmax(0,1fr)); }
}

.ftile{
  display:flex;
  flex-direction:column;
  gap:6px;
  padding:0;
  border:0;
  background:none;
  color:var(--muted);
  min-width:0;
  text-align:center;
}
.fthumb{
  position:relative;
  display:block;
  width:100%;
  aspect-ratio:1 / 1;
  border-radius:12px;
  overflow:hidden;
  background:var(--surface-2);
  box-shadow:inset 0 0 0 1px rgba(255,255,255,.05);
  transition:transform .14s ease, box-shadow .16s ease;
}
.fthumb canvas{ display:block; width:100%; height:100%; }
.ftile:active .fthumb{ transform:scale(.965); }
.ftile.is-active .fthumb{
  box-shadow:0 0 0 2px var(--accent), 0 8px 20px rgba(231,189,138,.22);
}
.ftile.is-active .fthumb::after{
  content:'';
  position:absolute;
  top:6px; inset-inline-end:6px;
  width:20px; height:20px;
  border-radius:50%;
  background:var(--accent);
  background-image:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23191307' stroke-width='3.6' stroke-linecap='round' stroke-linejoin='round'><path d='M20 6 9 17l-5-5'/></svg>");
  background-size:13px 13px;
  background-position:center;
  background-repeat:no-repeat;
  box-shadow:0 2px 7px rgba(0,0,0,.45);
}
.ftile.is-active .fname{ color:var(--accent); font-weight:600; }
.fname{
  font-size:11px;
  line-height:1.35;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
  max-width:100%;
}
.grid-empty{
  grid-column:1 / -1;
  padding:30px 12px;
  text-align:center;
  color:var(--muted);
  font-size:13.5px;
  line-height:1.8;
}

/* ---------- toast ---------- */
.toast{
  position:fixed;
  left:50%;
  bottom:24px;
  transform:translate(-50%, 18px);
  opacity:0;
  pointer-events:none;
  z-index:80;
  max-width:calc(100% - 36px);
  padding:10px 18px;
  border-radius:99px;
  background:rgba(30,32,37,.97);
  border:1px solid var(--line-2);
  color:var(--text);
  font-size:13.5px;
  text-align:center;
  box-shadow:0 14px 34px rgba(0,0,0,.55);
  transition:opacity .22s ease, transform .22s ease;
}
.toast.show{ opacity:1; transform:translate(-50%, 0); }

/* ---------- desktop ---------- */
@media (min-width:900px){
  .app{
    display:grid;
    grid-template-columns: minmax(0,1fr) 400px;
    grid-template-rows: auto minmax(0,1fr);
  }
  .topbar{ grid-column:1 / -1; padding:11px 22px; }
  .stage{ grid-column:1; grid-row:2; }
  .dock{
    grid-column:2; grid-row:2;
    height:auto;
    border-radius:0;
    border-top:0;
    border-inline-start:1px solid var(--line);
    box-shadow:none;
  }
  .dock-grip{ display:none; }
  .dock-top{ padding-top:16px; }
  .grid{ grid-template-columns:repeat(3, minmax(0,1fr)); }
  .photo-area{ padding:22px; }
  .stage-bar{ padding:10px 22px 12px; }
  .empty-mark{ font-size:62px; }
  .empty h1{ font-size:26px; }
}

@media (min-width:1280px){
  .app{ grid-template-columns: minmax(0,1fr) 440px; }
  .grid{ grid-template-columns:repeat(4, minmax(0,1fr)); }
}

/* ---------- short screens ---------- */
@media (max-height:640px){
  .stage-bar{ padding:6px 12px 8px; gap:5px; }
  .bar-row .icon-btn{ width:40px; height:40px; }
  .empty-mark{ font-size:40px; }
  .empty h1{ font-size:19px; }
  .empty p{ font-size:13px; }
}

@media (prefers-reduced-motion: reduce){
  *{
    transition-duration:.001ms !important;
    animation-duration:.001ms !important;
  }
  .ftile:active .fthumb{ transform:none; }
}

/* =========================================================
   شاشة الإقلاع (فلاتر أمير)
   ========================================================= */
.boot{
  position:fixed;
  inset:0;
  z-index:200;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:26px;
  overflow:hidden;
  background:
    radial-gradient(76% 54% at 50% 32%, rgba(231,189,138,.14) 0%, rgba(231,189,138,0) 62%),
    radial-gradient(130% 96% at 50% 0%, #1c1b1f 0%, #0a0b0d 60%),
    #08090b;
  transition:opacity .6s ease, transform .6s ease;
}
.boot::before{
  content:'';
  position:absolute;
  top:-46%;
  left:50%;
  width:150%;
  aspect-ratio:1 / 1;
  transform:translateX(-50%);
  background:radial-gradient(closest-side, rgba(231,189,138,.16), rgba(231,189,138,0) 72%);
  animation:bootBeam 5.4s ease-in-out infinite;
  pointer-events:none;
}
.boot.is-leaving{ opacity:0; transform:scale(1.05); pointer-events:none; }
.boot.is-done{ display:none; }

@keyframes bootBeam{
  0%,100%{ opacity:.45; transform:translateX(-50%) scale(.94); }
  50%{ opacity:.95; transform:translateX(-50%) scale(1.06); }
}

.boot-stage{
  position:relative;
  display:flex;
  flex-direction:column;
  align-items:center;
  gap:13px;
  width:100%;
  max-width:340px;
  text-align:center;
}

.emblem{
  position:relative;
  width:132px;
  height:132px;
  display:grid;
  place-items:center;
  filter:drop-shadow(0 18px 32px rgba(0,0,0,.62)) drop-shadow(0 0 26px rgba(231,189,138,.26));
  animation:emblemIn .95s cubic-bezier(.16,.9,.24,1) both, emblemFloat 6s ease-in-out 1s infinite;
}
@keyframes emblemIn{
  from{ opacity:0; transform:scale(.5) rotate(-26deg); }
  to{ opacity:1; transform:scale(1) rotate(0deg); }
}
@keyframes emblemFloat{
  0%,100%{ transform:translateY(0); }
  50%{ transform:translateY(-7px); }
}
.emblem-halo{
  position:absolute;
  inset:-20px;
  border-radius:50%;
  background:radial-gradient(closest-side, rgba(231,189,138,.24), rgba(231,189,138,0) 72%);
  animation:haloPulse 3.6s ease-in-out infinite;
  pointer-events:none;
}
@keyframes haloPulse{
  0%,100%{ opacity:.5; transform:scale(.9); }
  50%{ opacity:1; transform:scale(1.08); }
}
.emblem-svg{ position:relative; width:100%; height:100%; display:block; }
.iris{ transform-box:fill-box; transform-origin:center; animation:irisSpin 28s linear infinite; }
@keyframes irisSpin{ to{ transform:rotate(360deg); } }

.boot-name{
  margin:4px 0 0;
  font-size:30px;
  font-weight:700;
  line-height:1.35;
  background:linear-gradient(160deg, #fdeacb 8%, #e7bd8a 48%, #b57f42 96%);
  -webkit-background-clip:text;
  background-clip:text;
  color:transparent;
  animation:bootFadeUp .8s ease-out .5s both;
}
.boot-sub{
  margin:0;
  font-size:13px;
  color:var(--muted);
  animation:bootFadeUp .8s ease-out .68s both;
}
@keyframes bootFadeUp{
  from{ opacity:0; transform:translateY(12px); }
  to{ opacity:1; transform:translateY(0); }
}

.boot-progress{
  width:128px;
  height:3px;
  border-radius:99px;
  background:rgba(255,255,255,.10);
  overflow:hidden;
  animation:bootFadeUp .6s ease-out .82s both;
}
.boot-progress span{
  display:block;
  height:100%;
  width:0;
  border-radius:99px;
  background:linear-gradient(90deg, rgba(231,189,138,.25), var(--accent));
  animation:loadFill 1.9s cubic-bezier(.4,.1,.2,1) .9s forwards;
}
@keyframes loadFill{ to{ width:100%; } }

.boot-start{
  margin-top:6px;
  height:48px;
  padding:0 36px;
  border-radius:99px;
  border:1px solid rgba(231,189,138,.5);
  background:linear-gradient(150deg, var(--accent-2), #dfae74);
  color:var(--accent-ink);
  font-size:15px;
  font-weight:700;
  opacity:0;
  transform:translateY(10px);
  pointer-events:none;
  transition:opacity .45s ease, transform .45s ease;
}
.boot.is-ready .boot-start{
  opacity:1;
  transform:translateY(0);
  pointer-events:auto;
  animation:btnPulse 2.4s ease-in-out infinite;
}
.boot-start:active{ transform:scale(.96); }
@keyframes btnPulse{
  0%,100%{ box-shadow:0 12px 30px rgba(231,189,138,.18); }
  50%{ box-shadow:0 14px 44px rgba(231,189,138,.45); }
}

@media (max-height:560px){
  .boot-stage{ gap:10px; max-width:300px; }
  .emblem{ width:98px; height:98px; }
  .boot-name{ font-size:23px; }
  .boot-sub{ font-size:12px; }
  .boot-start{ height:44px; padding:0 28px; font-size:14px; margin-top:2px; }
}
@media (max-height:400px){
  .emblem{ width:74px; height:74px; }
  .boot-name{ font-size:19px; }
  .boot-sub{ display:none; }
  .boot-progress{ display:none; }
  .boot-start{ height:40px; }
}

@media (prefers-reduced-motion: reduce){
  .emblem,
  .boot.is-ready .boot-start,
  .emblem-halo,
  .iris,
  .boot::before{ animation:none !important; }
  .boot-name, .boot-sub, .boot-progress{ animation-delay:0s !important; }
}