/* =====================================================================
   Khlliha Tsarh — feuille de style
   Mobile first, RTL natif (dir="rtl") : uniquement des propriétés logiques
   (margin-inline, padding-inline, inset-inline...) pour que tout s'inverse seul.
   ===================================================================== */

:root {
  --red: #c1272d;          /* rouge du drapeau */
  --red-ink: #9e1c22;
  --green: #006233;        /* vert du drapeau */
  --saffron: #f2a900;
  --bg: #fbf7f1;           /* sable clair */
  --surface: #ffffff;
  --surface-2: #f3ece2;
  --text: #1d1a17;
  --muted: #6c645b;
  --border: #e7ded2;
  --shadow: 0 1px 2px rgb(60 40 20 / .06), 0 6px 18px rgb(60 40 20 / .06);
  --radius: 16px;
  --font: "Cairo", "Noto Kufi Arabic", "Segoe UI", Tahoma, sans-serif;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #15120f;
  --surface: #1f1b17;
  --surface-2: #2a241e;
  --text: #f4ede4;
  --muted: #b3a89a;
  --border: #3a3129;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
  --red: #e2474d;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15120f;
    --surface: #1f1b17;
    --surface-2: #2a241e;
    --text: #f4ede4;
    --muted: #b3a89a;
    --border: #3a3129;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    --red: #e2474d;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
/* L'attribut hidden doit toujours gagner (sinon .btn { display:inline-flex } l'écrase) */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; height: auto; display: block; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }

.wrap { width: 100%; max-width: 1120px; margin-inline: auto; padding-inline: 16px; }
.narrow { max-width: 720px; }
.center { text-align: center; margin-block: 24px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.skip {
  position: absolute; inset-inline-start: 8px; top: -100px;
  background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: 8px; z-index: 100;
}
.skip:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--saffron); outline-offset: 2px; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-block-end: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 12px; min-height: 60px; }
.logo { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 800; font-size: 1.2rem; }
.logo-mark {
  width: 44px; height: 48px; object-fit: contain;
  filter: drop-shadow(0 2px 4px rgb(0 0 0 / .18));
  transition: transform .2s;
}
.logo:hover .logo-mark { transform: rotate(-6deg) scale(1.05); }
.footer-logo { width: 74px; height: 80px; object-fit: contain; }
.topnav { display: none; gap: 20px; margin-inline-start: auto; }
.topnav a { text-decoration: none; font-weight: 600; color: var(--muted); }
.topnav a:hover { color: var(--red); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface);
}
/* Sélecteur عربي | FR : toujours visible, même sur mobile (menu masqué) */
.lang-switch {
  display: flex; gap: 2px; padding: 3px; margin-inline-start: auto; border-radius: 99px;
  background: var(--surface-2); font-size: .85rem; font-weight: 700; line-height: 1;
}
.lang-switch a { padding: 7px 10px; border-radius: 99px; text-decoration: none; color: var(--muted); }
.lang-switch a[aria-current] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

@media (min-width: 720px) {
  .topnav { display: flex; }
  .lang-switch { margin-inline-start: 0; }
}

/* ---------- Sections ---------- */
.section { padding-block: 28px; }
.section-alt { background: var(--surface-2); }
.hero { padding-block: 20px 4px; }
.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.section-title { font-size: 1.35rem; font-weight: 800; margin: 0 0 14px; }

/* ---------- Chips (catégories) & onglets ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding-block-end: 6px; margin-block-end: 14px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; scroll-snap-align: start;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; border-radius: 999px; text-decoration: none; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: .95rem;
}
.chip small { color: var(--muted); font-weight: 400; }
.chip.is-active { background: var(--red); border-color: var(--red); color: #fff; }
.chip.is-active small { color: rgb(255 255 255 / .8); }
.chip-sm { padding: 2px 10px; font-size: .8rem; }

.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-block-end: 18px; width: fit-content; }
.tab { padding: 6px 14px; border-radius: 9px; text-decoration: none; font-weight: 600; color: var(--muted); }
.tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Grille de cartes ---------- */
.grid { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 680px)  { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  display: flex; flex-direction: column; gap: 10px;
  padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: rise .35s ease both;
}
.card-featured {
  border: 2px solid var(--saffron);
  background: linear-gradient(160deg, color-mix(in srgb, var(--saffron) 12%, var(--surface)), var(--surface) 60%);
}
.card-featured .card-body { font-size: 1.15rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .8rem; }
.card-title { margin: 0; font-size: 1.05rem; font-weight: 800; line-height: 1.5; }
.card-title a { text-decoration: none; }
.card-body { margin: 0; font-size: 1.05rem; white-space: normal; flex: 1; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .card { animation: none; } html { scroll-behavior: auto; } }

/* ---------- Partage ---------- */
.share { display: flex; flex-wrap: wrap; gap: 6px; padding-block-start: 10px; border-block-start: 1px dashed var(--border); }
.btn-like, .btn-share {
  display: inline-flex; align-items: center; gap: 4px; min-height: 36px;
  padding: 4px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); text-decoration: none; font-size: .85rem; font-weight: 600;
}
.btn-like { margin-inline-end: auto; }
.btn-like.is-liked { background: var(--saffron); border-color: var(--saffron); color: #1d1a17; }
.btn-like.pop { animation: pop .4s ease; }
@keyframes pop { 50% { transform: scale(1.18); } }
.btn-share.wa { background: #25d366; border-color: #25d366; color: #fff; }
.btn-share.fb { background: #1877f2; border-color: #1877f2; color: #fff; }
.btn-share.ig { background: linear-gradient(45deg, #f58529, #dd2a7b, #8134af); border: 0; color: #fff; }

/* ---------- Façades vidéo ---------- */
.facade {
  position: relative; display: block; width: 100%; padding: 0; border: 0;
  aspect-ratio: 16 / 9; border-radius: 12px; overflow: hidden; background: #000;
}
.facade img { width: 100%; height: 100%; object-fit: cover; transition: transform .3s; }
.facade:hover img { transform: scale(1.03); }
.play {
  position: absolute; inset: 0; margin: auto; width: 64px; height: 64px; border-radius: 50%;
  background: rgb(193 39 45 / .92); box-shadow: 0 4px 20px rgb(0 0 0 / .35);
}
/* triangle "lecture" : pointe vers la droite même en RTL (convention universelle) */
.play::after {
  content: ""; position: absolute; top: 50%; left: 54%; transform: translate(-50%, -50%);
  border-style: solid; border-width: 12px 0 12px 20px; border-color: transparent transparent transparent #fff;
}
.facade iframe, .facade video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

.rail {
  display: grid; grid-auto-flow: column; grid-auto-columns: 78%; gap: 14px;
  overflow-x: auto; scroll-snap-type: x mandatory; padding-block-end: 8px;
}
@media (min-width: 680px) { .rail { grid-auto-columns: 40%; } }
@media (min-width: 1000px) { .rail { grid-auto-columns: 30%; } }
.video-card { scroll-snap-align: start; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border-radius: var(--radius); padding: 10px; border: 1px solid var(--border); }

/* ---------- Réseaux sociaux ---------- */
.grid-social .facade { aspect-ratio: 9 / 12; }
.social-card { display: flex; flex-direction: column; gap: 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.social-head { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; color: var(--muted); }
.social-caption { margin: 0; font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.social-link { font-weight: 600; font-size: .85rem; color: var(--red); text-decoration: none; margin-block-start: auto; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px;
  font-size: .8rem; font-weight: 700; color: #fff; text-decoration: none; }
.badge-youtube   { background: #ff0000; }
.badge-tiktok    { background: #111; }
.badge-instagram { background: linear-gradient(45deg, #f58529, #dd2a7b, #8134af); }
.badge-facebook  { background: #1877f2; }
.follow-inline { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 8px 26px; border-radius: 12px; border: 0; font-weight: 800; text-decoration: none; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-ink); }
.btn[disabled] { opacity: .6; cursor: progress; }

/* ---------- Pied de page ---------- */
.footer { border-block-start: 1px solid var(--border); padding-block: 28px; margin-block-start: 20px; }
.footer-inner { display: grid; gap: 14px; }
.follow { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; inset-inline: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); margin-inline: auto;
  max-width: 360px; padding: 10px 16px; border-radius: 12px; text-align: center;
  background: var(--text); color: var(--bg); font-weight: 600;
  opacity: 0; transform: translateY(10px); transition: .25s; pointer-events: none; z-index: 50;
}
.toast.show { opacity: 1; transform: none; }

/* ---------- Proposer une blague ---------- */
.nav-cta { color: var(--red) !important; }
.cta-submit {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  margin-block-start: 24px; padding: 16px 18px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--saffron) 14%, var(--surface)); border: 1px dashed var(--saffron);
}
.cta-submit p { margin: 0; }
.submit-form { gap: 14px; }
.submit-form label { display: grid; gap: 6px; font-weight: 600; }
.submit-form textarea, .submit-form input, .submit-form select {
  font: inherit; color: var(--text); background: var(--bg); width: 100%;
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
}
.submit-form textarea { resize: vertical; line-height: 1.8; }
.lang-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 18px; border: 0; padding: 0; margin: 0; min-width: 0; }
.lang-pick legend { font-weight: 600; padding: 0; margin-block-end: 6px; }
.submit-form .lang-pick label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.submit-form .lang-pick input { width: auto; accent-color: var(--red); }
.submit-row { display: grid; gap: 14px; }
@media (min-width: 640px) { .submit-row { grid-template-columns: 1fr 1fr; } }
.submit-done { gap: 16px; }
.hp { position: absolute; inset-inline-start: -9999px; width: 1px; height: 1px; overflow: hidden; }
.alert { padding: 10px 14px; border-radius: 12px; margin-block-end: 14px; font-weight: 600;
  background: color-mix(in srgb, var(--red) 12%, var(--surface)); color: var(--red); }

/* ---------- Commentaires ---------- */
.btn-like { margin-inline-end: 0; }
.btn-share.cmt { margin-inline-end: auto; }
.comments { margin-block: 28px; }
.comment-form { gap: 10px; }
.comment-form input, .comment-form textarea {
  font: inherit; color: var(--text); background: var(--bg); width: 100%;
  border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px;
}
.comment-form textarea { resize: vertical; line-height: 1.7; }
.comment-form-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.comment-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.comment { padding: 12px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.comment-head { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.comment-head time { color: var(--muted); font-size: .8rem; }
.comment-body { margin: 4px 0 0; white-space: normal; overflow-wrap: anywhere; }
.comment-empty { text-align: center; padding: 16px; }
.link-btn { background: none; border: 0; padding: 0; color: var(--muted); font-size: .78rem; margin-block-start: 4px; }
.link-btn:hover { color: var(--red); }

/* ---------- Auteur & classement ---------- */
.card-author { margin: 0; font-size: .85rem; color: var(--muted); }
.card-author strong { color: var(--text); }
.leaderboard { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.lb-row {
  display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border);
}
.lb-podium { border-color: var(--saffron); background: color-mix(in srgb, var(--saffron) 8%, var(--surface)); }
.lb-rank { font-size: 1.5rem; text-align: center; line-height: 1; }
.rank-num { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); font-size: .9rem; font-weight: 800; }
.lb-main { display: grid; min-width: 0; }
.lb-name { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-best { font-size: .82rem; color: var(--muted); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-best:hover { color: var(--red); }
.lb-stats { display: flex; gap: 10px; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--red); }
@media (max-width: 480px) { .lb-stats span[title="😂"] { display: none; } }

/* ---------- Carte-image ---------- */
.btn-share.img { background: linear-gradient(135deg, var(--saffron), var(--red)); border: 0; color: #fff; }
.btn-share[disabled] { opacity: .7; cursor: progress; }

/* ---------- Tags ---------- */
.card-tags { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: .82rem; font-weight: 600; color: var(--red); text-decoration: none; background: var(--surface-2); padding: 2px 10px; border-radius: 99px; }
.tag:hover { text-decoration: underline; }

/* ---------- OCR (photo -> texte) ---------- */
.ocr-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.btn-ocr { background: var(--surface-2); border: 1px dashed var(--saffron); color: var(--text); min-height: 42px; font-weight: 700; }
