/* ---------- Fonts (self-hosted Cairo, OFL) ---------- */
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 400; src: url(../fonts/cairo-arabic-400-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 600; src: url(../fonts/cairo-arabic-600-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 700; src: url(../fonts/cairo-arabic-700-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 800; src: url(../fonts/cairo-arabic-800-normal.woff2) format('woff2'); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0897-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 400; src: url(../fonts/cairo-latin-400-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 600; src: url(../fonts/cairo-latin-600-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 700; src: url(../fonts/cairo-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: Cairo; font-style: normal; font-display: swap; font-weight: 800; src: url(../fonts/cairo-latin-800-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --c1: #1e1b4b;
  --c2: #06b6d4;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6475;
  --border: #e3e8f0;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --font: Cairo, "Segoe UI", Tahoma, Arial, sans-serif;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}
body.has-photo { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
body.has-photo #step-photo { display: none; }
.frames-block { margin: 4px 0 14px; }
img, canvas { max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; inset-inline-start: 12px; top: -60px; background: #fff; padding: 8px 14px; border-radius: 10px; z-index: 50; }
.skip:focus { top: 12px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--c2) 70%, #fff); outline-offset: 2px; }

/* ---------- Hero ---------- */
.hero {
  background: radial-gradient(1200px 400px at 100% 0%, color-mix(in srgb, var(--c2) 55%, transparent), transparent 60%),
              linear-gradient(135deg, var(--c1), color-mix(in srgb, var(--c1) 60%, var(--c2)));
  color: #fff;
  padding: 14px 16px 64px;
  transition: background .4s ease;
}
.hero-bar { max-width: 1100px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; }
.brand img { border-radius: 10px; background: rgba(255,255,255,.12); }
.lang-btn { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 999px; padding: 6px 16px; cursor: pointer; font-weight: 600; }
.lang-btn:hover { background: rgba(255,255,255,.24); }
.hero-text { max-width: 1100px; margin: 26px auto 0; }
.hero h1 { font-size: clamp(1.5rem, 4.6vw, 2.4rem); line-height: 1.3; margin: 0 0 8px; font-weight: 800; }
.hero p { margin: 0; opacity: .9; max-width: 640px; }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: -40px auto 0; padding: 0 16px 32px; position: relative; counter-reset: step; }
.step { counter-increment: step; }
.step-num::before { content: counter(step); }
.step { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; transition: opacity .3s; }
.step.is-locked { opacity: .55; }
.step-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.step-head h2 { margin: 0; font-size: 1.15rem; font-weight: 800; flex: 1; }
.step-num {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--c1), var(--c2)); color: #fff; font-weight: 800;
}
.link-btn { background: none; border: 0; color: var(--c1); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 4px; }
.empty { color: var(--muted); padding: 12px; background: var(--bg); border-radius: 12px; margin: 0; }
.hint { color: var(--muted); font-size: .9rem; margin: 8px 0; }
.hint.small { font-size: .82rem; }

/* ---------- Projects ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.project-card {
  --pc1: var(--c1); --pc2: var(--c2);
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  padding: 18px 12px 14px; border-radius: 16px; cursor: pointer;
  background: var(--card); border: 2px solid var(--border);
  position: relative; overflow: hidden; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.project-card::before { content: ""; position: absolute; inset: 0 0 auto; height: 5px; background: linear-gradient(90deg, var(--pc1), var(--pc2)); }
.project-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.project-card[aria-checked="true"] { border-color: var(--pc1); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pc2) 25%, transparent); }
.pc-logo {
  width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(135deg, var(--pc1), var(--pc2)); color: #fff; font-weight: 800; font-size: 1.3rem;
}
.pc-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 6px; }
.pc-name { font-weight: 800; font-size: 1.05rem; }
.pc-meta { font-size: .8rem; color: var(--muted); }
#step-project.collapsed .project-card[aria-checked="false"] { display: none; }
#step-project.collapsed .project-grid { grid-template-columns: minmax(0, 260px); }
#step-project.collapsed .project-card { flex-direction: row; text-align: start; padding: 12px; }
#step-project.collapsed .pc-logo { width: 44px; height: 44px; font-size: 1rem; border-radius: 12px; }
#step-project.collapsed .pc-meta { display: none; }

/* ---------- Upload ---------- */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  border: 2px dashed color-mix(in srgb, var(--c1) 35%, var(--border)); border-radius: 16px; padding: 28px 16px;
  cursor: pointer; background: color-mix(in srgb, var(--c2) 5%, #fff); transition: background .15s, border-color .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--c1); background: color-mix(in srgb, var(--c2) 12%, #fff); }
.dropzone:focus-within { outline: 3px solid color-mix(in srgb, var(--c2) 70%, #fff); }
.dz-icon { color: var(--c1); }
.dropzone small { color: var(--muted); }
.privacy { margin: 12px 0 0; font-size: .9rem; color: #166534; background: #f0fdf4; border-radius: 10px; padding: 8px 12px; }

/* ---------- Editor ---------- */
.editor { display: grid; gap: 18px; }
@media (min-width: 900px) { .editor { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; } }
.format-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.tab {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); font-weight: 700; font-size: .92rem;
}
.tab[aria-selected="true"] { background: var(--c1); color: #fff; border-color: var(--c1); }
.tab-icon { display: inline-block; border: 2px solid currentColor; border-radius: 3px; width: 14px; height: 14px; }
.fmt-profile .tab-icon { border-radius: 50%; }
.fmt-story .tab-icon { width: 10px; height: 17px; }
.fmt-cover .tab-icon { width: 20px; height: 8px; }
.stage { display: flex; justify-content: center; }
.canvas-wrap { position: relative; line-height: 0; }
#preview {
  display: block; border-radius: 14px; box-shadow: 0 10px 30px rgba(15,23,42,.18); background: #e2e8f0;
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
}
#preview.dragging { cursor: grabbing; }
.canvas-wrap.circle #preview { clip-path: circle(50% at 50% 50%); border-radius: 50%; }
.busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(15, 23, 42, .55); color: #fff; border-radius: 14px; line-height: 1.5; text-align: center; padding: 16px; font-weight: 700;
}
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid rgba(255,255,255,.35); border-top-color: #fff; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.stage-col .hint { text-align: center; }
.controls { display: grid; gap: 10px; }
.range { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 10px; font-weight: 600; font-size: .92rem; }
input[type="range"] { width: 100%; accent-color: var(--c1); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; font-size: .92rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-ui { width: 42px; height: 24px; border-radius: 999px; background: #cbd5e1; position: relative; transition: background .15s; flex: none; }
.switch-ui::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: inset-inline-start .15s; }
.switch input:checked + .switch-ui { background: var(--c1); }
.switch input:checked + .switch-ui::after { inset-inline-start: 21px; }
.switch input:focus-visible + .switch-ui { outline: 3px solid color-mix(in srgb, var(--c2) 70%, #fff); }

.panel-col { display: grid; gap: 14px; }
.panel-block { border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.panel-block h3, .panel-block summary { margin: 0 0 10px; font-size: 1rem; font-weight: 800; }
details.panel-block summary { cursor: pointer; margin: 0; }
details[open].panel-block summary { margin-bottom: 10px; }
details.panel-block .range { margin-bottom: 8px; }
.smart { background: linear-gradient(135deg, color-mix(in srgb, var(--c1) 6%, #fff), color-mix(in srgb, var(--c2) 8%, #fff)); }
.frame-list { display: flex; flex-wrap: wrap; gap: 10px; }
.frame-thumb {
  padding: 4px; border-radius: 12px; border: 2px solid var(--border); background: #fff; cursor: pointer; line-height: 0;
  transition: border-color .15s, transform .15s;
}
.frame-thumb:hover { transform: translateY(-2px); }
.frame-thumb[aria-checked="true"] { border-color: var(--c1); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c2) 30%, transparent); }
.frame-thumb canvas { border-radius: 8px; display: block; }
.field { display: grid; gap: 4px; margin-bottom: 10px; font-weight: 600; font-size: .92rem; }
.field input, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: #fff;
}
.field input:focus, textarea:focus { border-color: var(--c1); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c2) 25%, transparent); }
.seg { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.seg-label { font-weight: 700; font-size: .9rem; margin-inline-end: 4px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg span:not(.seg-label) { display: inline-block; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); background: #fff; font-size: .88rem; font-weight: 600; }
.seg input:checked + span { background: var(--c1); border-color: var(--c1); color: #fff; }
.seg input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--c2) 70%, #fff); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 12px; padding: 9px 16px;
  border: 1px solid var(--border); background: #fff; cursor: pointer; font-weight: 700; font-size: .95rem; text-decoration: none;
  transition: transform .1s, box-shadow .15s, background .15s;
}
.btn:hover:not(:disabled) { box-shadow: var(--shadow); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--bg); }
.btn.sm { padding: 6px 12px; font-size: .85rem; }
.btn.primary { background: linear-gradient(135deg, var(--c1), color-mix(in srgb, var(--c1) 55%, var(--c2))); color: #fff; border: 0; }
.btn.secondary { background: #fff; color: var(--c1); border: 2px solid var(--c1); }
.btn.big { padding: 12px 22px; font-size: 1.05rem; border-radius: 14px; }

/* ---------- Share ---------- */
.share-grid { display: grid; gap: 16px; }
@media (min-width: 800px) { .share-grid { grid-template-columns: 1.4fr 1fr; } }
.caption-box { display: grid; gap: 8px; }
.caption-box label { font-weight: 700; }
.caption-box textarea { resize: vertical; min-height: 120px; background: var(--bg); }
.caption-box .btn { justify-self: start; }
.share-tips { display: grid; gap: 10px; align-content: start; color: var(--muted); }
.share-tips .btn { justify-self: start; }

.action-bar {
  position: fixed; inset: auto 0 0 0; z-index: 30; display: flex; justify-content: center; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-top: 1px solid var(--border);
}
.action-bar .btn { flex: 1; max-width: 300px; }

.toast {
  position: fixed; top: 16px; inset-inline: 16px; margin: 0 auto; max-width: 520px; z-index: 60;
  background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow);
  font-weight: 600; text-align: center; transform: translateY(-140%); opacity: 0; transition: transform .25s, opacity .25s; pointer-events: none;
}
.toast.show { transform: none; opacity: 1; }
.toast.error { background: #b91c1c; }
.toast.ok { background: #15803d; }

.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 8px 16px 28px; }
.warn { background: #fff7ed; color: #9a3412; padding: 12px; border-radius: 12px; }

@media (max-width: 480px) {
  .step { padding: 14px; }
  .range { grid-template-columns: 74px 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
