:root {
  --ink: #141413;
  --paper: #ffffff;
  --bg: #f5f4ef;
  --card: #ffffff;
  --line: #e4e2da;
  --line-strong: #cfcdc4;
  --muted: #6b6a65;
  --soft: #efede6;
  --danger: #a32d2d;
  --danger-bg: #fcebeb;
  --on-ink: #ffffff;
  --radius: 16px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f5f4ef;
    --paper: #141413;
    --bg: #141413;
    --card: #1e1e1c;
    --line: #2f2f2c;
    --line-strong: #474743;
    --muted: #a3a19a;
    --soft: #2a2a27;
    --danger: #f09595;
    --danger-bg: #3a1c1c;
    --on-ink: #141413;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
a { color: inherit; }
p { margin: 0; }
h1, h2 { line-height: 1.3; }
[hidden] { display: none !important; }

.wrap { max-width: 560px; margin: 0 auto; padding: 16px 16px 72px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.page-title { font-size: 24px; margin: 8px 0 16px; }
.section-title { font-size: 18px; margin: 0; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 560px; margin: 0 auto; padding: 8px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; font-size: 20px; }
.nav { display: flex; align-items: center; gap: 6px; }

/* ---------- الباندا ---------- */
.avatar {
  border-radius: 50%; background: #fff; border: 2px solid #141413;
  display: grid; place-items: center; overflow: hidden; flex: none;
  width: 56px; height: 56px;
}
.avatar .panda { width: 88%; height: 88%; display: block; }
.avatar-sm { width: 36px; height: 36px; border-width: 1.5px; }
.avatar-md { width: 80px; height: 80px; }
.avatar-lg { width: 104px; height: 104px; }
.avatar-xl { width: 128px; height: 128px; }

/* ---------- الأيقونات والأزرار ---------- */
.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 15px; font-weight: 500; line-height: 1.2;
  min-height: 44px; padding: 10px 16px;
  border-radius: 12px; border: 1px solid var(--line-strong);
  background: transparent; color: var(--ink);
  text-decoration: none; cursor: pointer;
  transition: transform .1s ease, background-color .15s ease;
}
.btn:hover { background: var(--soft); }
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .6; cursor: progress; }
.btn-primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn-primary:hover { background: var(--ink); opacity: .9; }
.btn-lg { min-height: 52px; font-size: 17px; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn-icon { position: relative; width: 40px; min-height: 40px; padding: 0; border-color: transparent; }
.btn-danger { color: var(--danger); }
.badge {
  position: absolute; top: 2px; inset-inline-end: 0;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--ink); color: var(--on-ink);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 500;
  padding: 6px 12px; border-radius: 999px;
  background: var(--soft); color: var(--ink); border: 1px solid transparent; cursor: pointer;
}
.chip .ic { width: 18px; height: 18px; }
.chip input { width: 16px; height: 16px; margin: 0; accent-color: var(--ink); }

/* ---------- البطاقات والحقول ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card + .card, .card + section, section + .card { margin-top: 12px; }
label { display: block; font-size: 14px; font-weight: 500; }
input, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: inherit; font-size: 16px; font-weight: 400; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line-strong); border-radius: 12px;
  padding: 10px 12px;
}
textarea { resize: none; line-height: 1.6; }
input:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: 1px; border-color: var(--ink); }
input::placeholder, textarea::placeholder { color: var(--muted); }
.hint { display: block; margin-top: 6px; font-size: 13px; font-weight: 400; color: var(--muted); }
.form-error { color: var(--danger); background: var(--danger-bg); border-radius: 10px; padding: 8px 12px; font-size: 14px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input {
  appearance: none; -webkit-appearance: none;
  width: 46px; height: 28px; margin: 0; padding: 0; flex: none;
  border: 0; border-radius: 14px; background: var(--line-strong);
  position: relative; cursor: pointer; transition: background-color .15s ease;
}
.switch input::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--paper);
  transition: inset-inline-start .15s ease;
}
.switch input:checked { background: var(--ink); }
.switch input:checked::after { inset-inline-start: 21px; }

/* ---------- الصفحة الرئيسية والدخول ---------- */
.hero { text-align: center; padding: 28px 0 8px; }
.hero .avatar { margin: 0 auto 16px; }
.hero h1 { font-size: 34px; margin: 0 0 8px; }
.lead { font-size: 18px; color: var(--muted); max-width: 380px; margin: 0 auto 24px; }
.steps { list-style: none; padding: 0; margin: 32px 0 0; display: grid; gap: 10px; text-align: start; counter-reset: step; }
.steps li {
  counter-increment: step; display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.steps li::before {
  content: counter(step, arabic-indic);
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; background: var(--ink); color: var(--on-ink); font-weight: 700;
}
.steps b { display: block; }
.steps span { color: var(--muted); font-size: 14px; }

.auth { text-align: center; padding-top: 12px; }
.auth .avatar { margin: 0 auto 12px; }
.auth h1 { font-size: 26px; margin: 0 0 4px; }
.auth > .muted { margin-bottom: 16px; }
.auth form { text-align: start; margin-bottom: 16px; }
.link-preview { margin-top: 6px; overflow-wrap: anywhere; }

/* ---------- صفحة الملف الشخصي ---------- */
.profile { text-align: center; padding: 12px 0 4px; }
.profile .avatar { margin: 0 auto 10px; }
.profile h1 { font-size: 24px; margin: 0; }
.handle { color: var(--muted); }
.bio { margin-top: 8px; white-space: pre-wrap; }
.stat { margin-top: 8px; font-size: 14px; color: var(--muted); }
.stat b { color: var(--ink); }

.ask, .owner-note, #ask-done { margin-top: 16px; }
.ask-title { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.ask textarea { min-height: 120px; font-size: 17px; }
.ask-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 10px 0 12px; }
.counter { margin-inline-start: auto; font-size: 12px; color: var(--muted); }
.ask .form-error { margin-bottom: 12px; }
.lock-note { margin-top: 10px; display: flex; align-items: center; justify-content: center; gap: 6px; }
.lock-note .ic { width: 16px; height: 16px; }

.done { text-align: center; }
.done h2 { margin: 0 0 4px; font-size: 20px; }
.done-check {
  width: 56px; height: 56px; border-radius: 50%; margin: 4px auto 10px;
  display: grid; place-items: center; background: var(--ink); color: var(--on-ink);
}
.done-check .ic { width: 28px; height: 28px; stroke-width: 2.4; }
.done > .btn { margin-top: 14px; }
.cta { border-top: 1px dashed var(--line-strong); margin-top: 16px; padding-top: 16px; display: grid; gap: 10px; }

.answers { margin-top: 28px; }
.empty-note { padding: 20px 0; }
.qa { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: 10px; }
.qa-meta { font-size: 13px; color: var(--muted); }
.qa-meta a { color: var(--ink); text-decoration: none; font-weight: 500; }
.qa-q { font-weight: 700; font-size: 17px; margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.qa-a { margin-top: 8px; padding-inline-start: 12px; border-inline-start: 3px solid var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.qa-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; font-size: 13px; color: var(--muted); }
.qa-foot a { display: inline-flex; align-items: center; gap: 4px; text-decoration: none; color: var(--muted); }
.qa-foot .ic { width: 16px; height: 16px; }
.mini-profile { display: flex; align-items: center; gap: 10px; text-decoration: none; margin: 8px 0 4px; }
.mini-profile > span { display: flex; flex-direction: column; line-height: 1.3; }
.ask-too { margin-top: 16px; }

/* ---------- الوارد ---------- */
.linkcard-url { font-weight: 700; font-size: 17px; margin: 2px 0 12px; overflow-wrap: anywhere; text-align: right; }
.banner {
  display: block; margin-top: 12px; padding: 10px 14px; border-radius: 12px;
  background: var(--ink); color: var(--on-ink); text-decoration: none; font-size: 14px;
}
.tabs { display: flex; gap: 4px; padding: 4px; margin: 16px 0 12px; background: var(--soft); border-radius: 12px; }
.tabs button {
  flex: 1; font: inherit; font-size: 15px; font-weight: 500;
  padding: 8px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer;
}
.tabs button.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.count { font-size: 13px; }
.count:not(:empty)::before { content: "("; }
.count:not(:empty)::after { content: ")"; }
.refresh-bar {
  display: block; width: 100%; margin-bottom: 12px; padding: 10px;
  font: inherit; font-size: 14px; font-weight: 500;
  border: 1px dashed var(--ink); border-radius: 12px; background: var(--card); color: var(--ink); cursor: pointer;
}
.loading { padding: 32px 0; }

.q { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; transition: opacity .2s ease, transform .2s ease; }
.q + .q, .q + .empty { margin-top: 10px; }
.q.daily { border-style: dashed; border-color: var(--line-strong); }
.q.leaving { opacity: 0; transform: translateX(-12px); }
.q-meta { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.q-meta .who { color: var(--ink); font-weight: 500; }
.q-meta .ic { width: 16px; height: 16px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.q-body { font-size: 17px; font-weight: 700; margin: 6px 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.q-answer { background: var(--soft); border-radius: 12px; padding: 10px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.q textarea { margin-top: 0; min-height: 48px; }
.q .form-error { margin-top: 8px; }
.q-actions { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.q-actions .spacer { flex: 1; }
.q-actions .btn-icon { color: var(--muted); }

.empty { text-align: center; padding: 28px 12px; }
.empty .avatar { margin: 0 auto 12px; width: 80px; height: 80px; }
.empty-title { font-weight: 700; font-size: 18px; }
.empty p + p { color: var(--muted); margin: 4px 0 16px; }

/* ---------- نافذة المشاركة ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .15s ease;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 94vh; overflow: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  animation: rise .22s ease-out;
}
@media (min-width: 600px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 22px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.preview {
  display: block; width: min(210px, 52vw); aspect-ratio: 9 / 16; margin: 0 auto;
  border-radius: 14px; border: 1px solid var(--line); background: var(--soft); object-fit: cover;
}
.swatches { display: flex; justify-content: center; gap: 12px; margin: 14px 0; }
.swatch { width: 32px; height: 32px; padding: 0; border-radius: 50%; border: 2px solid var(--line-strong); cursor: pointer; }
.swatch[aria-pressed="true"] { outline: 2px solid var(--ink); outline-offset: 3px; }
.share-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.share-grid .btn { flex-direction: column; gap: 4px; min-height: 68px; padding: 8px 4px; font-size: 13px; }
.share-grid .ic { width: 22px; height: 22px; }
.sheet-hint { margin-top: 12px; font-size: 13px; color: var(--muted); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--ink); color: var(--on-ink); font-size: 14px; font-weight: 500;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: .5; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
