/* =========================================================================
   Su'āl — elegant, minimal, bilingual (EN/AR)
   A warm "paper" palette, refined serif display, generous whitespace,
   and quiet motion. Light + dark, LTR + RTL. Responsive across phone,
   tablet, and desktop (including notched / safe-area devices).
   ========================================================================= */

:root {
  --bg: #f6f2ec;
  --bg-tint: #ece4d8;
  --card: #fffdf9;
  --ink: #241f1a;
  --ink-soft: #4b443c;
  --muted: #938a7d;
  --line: rgba(36, 31, 26, 0.10);
  --line-strong: rgba(36, 31, 26, 0.16);
  --accent: #a8794a;      /* muted gold / terracotta */
  --accent-soft: #f0e6d6;
  --shadow: 0 18px 50px -24px rgba(45, 36, 25, 0.45);
  --shadow-soft: 0 4px 20px -12px rgba(45, 36, 25, 0.35);

  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-ar: 'Amiri', 'Segoe UI', 'Traditional Arabic', serif;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  /* Layout rhythm that scales with viewport */
  --page-pad-x: clamp(1rem, 4.5vw, 3rem);
  --page-pad-y: clamp(0.85rem, 2.5vw, 2rem);
  --stage-max: min(760px, 100%);
  --tap-min: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17140f;
    --bg-tint: #221d16;
    --card: #201b15;
    --ink: #efe7d9;
    --ink-soft: #cfc5b4;
    --muted: #9a9081;
    --line: rgba(239, 231, 217, 0.10);
    --line-strong: rgba(239, 231, 217, 0.18);
    --accent: #d6ac70;
    --accent-soft: #2b241a;
    --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.7);
    --shadow-soft: 0 6px 24px -14px rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over component display rules. */
[hidden] { display: none !important; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  padding:
    var(--safe-top)
    var(--safe-right)
    var(--safe-bottom)
    var(--safe-left);
}

/* Arabic UI uses the Amiri serif throughout */
:lang(ar) body,
html[lang='ar'] body { font-family: var(--font-ar); }

/* Soft ambient glow behind everything */
.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(60% 55% at 50% 8%, var(--accent-soft), transparent 70%),
    radial-gradient(90% 70% at 50% 120%, var(--bg-tint), transparent 60%);
  opacity: 0.9;
  pointer-events: none;
}

/* -------------------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: var(--page-pad-y) var(--page-pad-x);
  flex-shrink: 0;
}

.lang-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--card) 70%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  flex-shrink: 0;
}

.lang-toggle button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s var(--ease), background 0.25s var(--ease);
}
.lang-toggle button[data-lang-btn='ar'] { font-family: var(--font-ar); font-size: 1.05rem; }
.lang-toggle button:hover { color: var(--ink); }
.lang-toggle button.is-active {
  background: var(--ink);
  color: var(--bg);
}

/* -------------------------------------------------------------- stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 3vw, 2rem);
  width: 100%;
  max-width: var(--stage-max);
  margin: 0 auto;
  padding: clamp(0.5rem, 2vw, 1.5rem) var(--page-pad-x) clamp(2rem, 5vw, 3.5rem);
  text-align: center;
  min-height: 0;
}

/* Keep brand, card, and button stacked at stable sizes.
   The two filter rows have to be named here, not just the categories: each one
   sets overflow-x, which forces overflow-y to auto and makes the row a scroll
   container, and a scroll container's automatic minimum size is 0. Left out of
   this list a row silently collapses to its own padding while its 36px chips
   overflow and paint behind whatever sits below. */
.brand,
.tagline,
.level-filters,
.cat-filters,
.react-bar,
.actions {
  flex-shrink: 0;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.75rem, 8vw + 0.5rem, 4.75rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--ink);
  opacity: 0;
  animation: rise 0.9s var(--ease) forwards;
}
:lang(ar) .brand {
  font-family: var(--font-ar);
  font-size: clamp(3.25rem, 9vw + 0.6rem, 5.25rem);
  letter-spacing: 0;
  font-weight: 700;
}

.tagline {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 2.2vw, 1.15rem);
  font-weight: 400;
  letter-spacing: 0.02em;
  max-width: 28ch;
  padding-inline: 0.25rem;
  opacity: 0;
  animation: rise 0.9s var(--ease) 0.12s forwards;
}

/* Quiet category filter — one tap, no chrome */
.cat-filters {
  display: flex;
  flex-wrap: nowrap;
  justify-content: safe center;
  gap: 0.35rem;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0.15rem 0.1rem;
  opacity: 0;
  animation: rise 0.9s var(--ease) 0.2s forwards;
}
.cat-filters::-webkit-scrollbar { display: none; }

.cat-chip {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  padding: 0.45rem 0.85rem;
  min-height: 36px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s var(--ease), background 0.25s var(--ease);
}
.cat-chip:hover { color: var(--ink); }
.cat-chip.is-active {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-soft) 85%, var(--card));
}
.cat-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:lang(ar) .cat-chip,
.cat-chip:lang(ar) {
  font-family: var(--font-ar);
  font-size: 0.95rem;
  letter-spacing: 0;
}

/* Difficulty row — sits above the categories, same chip language.
   A dot carries the level so the three read as a scale at a glance. */
.level-filters {
  display: flex;
  flex-wrap: nowrap;
  justify-content: safe center;
  gap: 0.35rem;
  width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0.15rem 0.1rem;
  opacity: 0;
  animation: rise 0.9s var(--ease) 0.15s forwards;
}
.level-filters::-webkit-scrollbar { display: none; }
.level-chip { display: inline-flex; align-items: center; gap: 0.4rem; }
.level-chip.level-easy::before,
.level-chip.level-medium::before,
.level-chip.level-hard::before {
  content: '';
  width: 0.42em;
  height: 0.42em;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}
.level-chip.level-medium::before { opacity: 0.7; }
.level-chip.level-hard::before { opacity: 1; }
.level-chip.is-active::before { opacity: 1; }

/* The question card — fixed height so the button never jumps */
.card {
  position: relative;
  width: 100%;
  height: clamp(200px, 30vh, 280px);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  padding: clamp(1.25rem, 4vw, 2.4rem);
  border-radius: clamp(18px, 4vw, 26px);
  border: 1px solid transparent;
  overflow: auto;
  overscroll-behavior: contain;
  transition: border-color 0.6s var(--ease), box-shadow 0.6s var(--ease),
    background 0.6s var(--ease);
}
.card.has-content {
  border-color: var(--line);
  background: var(--card);
  box-shadow: var(--shadow);
}

/* The tags above the question: how hard it is, then what it is about. One row
   so they read as a single line of context, wrapping instead of overflowing on
   a narrow phone. */
.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  max-width: 100%;
}

/* Same shape as the category pill, but filled — it is a rating, not a label,
   and carries the same dot scale as the difficulty filter above. */
.q-level {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.35em 0.8em;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-soft) 45%, transparent);
}
.q-level::before {
  content: '';
  width: 0.42em;
  height: 0.42em;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.45;
}
.q-level.level-medium::before { opacity: 0.7; }
.q-level.level-hard::before { opacity: 1; }
/* What kind of question it is. Outlined rather than filled so it reads as a
   different axis from the difficulty pill sitting next to it. */

:lang(ar) .q-level,
.q-level:lang(ar) {
  font-family: var(--font-ar);
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.85rem;
}

.eyebrow {
  display: inline-block;
  flex-shrink: 0;
  font-family: var(--font-ui);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 0.35em 0.9em;
  border: 1px solid var(--line);
  border-radius: 999px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.eyebrow:lang(ar),
:lang(ar) .eyebrow {
  font-family: var(--font-ar);
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.85rem;
}

.question {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.25rem, 3.2vw + 0.4rem, 2.4rem);
  line-height: 1.35;
  color: var(--ink);
  letter-spacing: -0.01em;
  max-width: 22ch;
  width: 100%;
  overflow-wrap: anywhere;
  hyphens: auto;
}
/* Arabic questions: Amiri, roomier line height, no negative tracking */
.question:lang(ar) {
  font-family: var(--font-ar);
  line-height: 1.7;
  letter-spacing: 0;
  max-width: 26ch;
  font-size: clamp(1.35rem, 3.5vw + 0.4rem, 2.5rem);
}

/* Reveal animation applied fresh on each new question */
.question.enter { animation: rise 0.7s var(--ease) forwards; }

.card.reveal-pulse {
  animation: card-pulse 0.65s var(--ease);
}
@keyframes card-pulse {
  0% { transform: scale(0.985); }
  45% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

/* Like / dislike / share */
.react-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  flex-shrink: 0;
  opacity: 0;
  animation: rise 0.55s var(--ease) forwards;
}
.react-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  min-height: 40px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s var(--ease), background 0.25s var(--ease),
    border-color 0.25s var(--ease);
}
.react-btn:hover { color: var(--ink); border-color: var(--line-strong); }
.react-btn.is-active,
.react-btn[aria-pressed='true'] {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent-soft) 90%, var(--card));
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}
.react-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
:lang(ar) .react-btn { font-family: var(--font-ar); font-size: 0.95rem; }

.react-toast {
  margin: 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}
:lang(ar) .react-toast { font-family: var(--font-ar); }

/* Share channel menu */
.share-menu {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  flex-shrink: 0;
  opacity: 0;
  animation: rise 0.4s var(--ease) forwards;
}
.share-opt {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease);
}
.share-opt:hover { color: var(--ink); border-color: var(--line-strong); }
/* Brand marks keep their own colour; the rest follow the button's text. */
.share-opt-icon {
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
  fill: currentColor;
}
.share-opt-icon.is-whatsapp { fill: #25d366; }
.share-opt-icon.is-facebook { fill: #1877f2; }
.share-opt-icon.is-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
:lang(ar) .share-opt { font-family: var(--font-ar); font-size: 0.9rem; }

/* Optional "why did you dislike this?" chips */
.reason-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  flex-shrink: 0;
  opacity: 0;
  animation: rise 0.45s var(--ease) forwards;
}
.reason-prompt {
  color: var(--muted);
  font-size: 0.82rem;
}
:lang(ar) .reason-prompt { font-family: var(--font-ar); }
.reason-chip {
  appearance: none;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  color: var(--muted);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.25s var(--ease), border-color 0.25s var(--ease);
}
.reason-chip:hover { color: var(--ink); border-color: var(--line-strong); }
:lang(ar) .reason-chip { font-family: var(--font-ar); font-size: 0.9rem; }

/* Session counter + streak */
.session-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-align: center;
  flex-shrink: 0;
  opacity: 0;
  animation: rise 0.55s var(--ease) forwards;
}
:lang(ar) .session-note { font-family: var(--font-ar); font-size: 0.88rem; }

/* -------------------------------------------------------------- actions */
.actions {
  display: flex;
  justify-content: center;
  width: 100%;
  max-width: 100%;
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 1.02rem;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.95rem 2.2rem;
  min-height: var(--tap-min);
  max-width: 100%;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s var(--ease), box-shadow 0.3s var(--ease),
    background 0.3s var(--ease), opacity 0.3s var(--ease);
}
:lang(ar) .btn { font-family: var(--font-ar); font-size: 1.2rem; }

.btn-primary {
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow-soft);
}
@media (hover: hover) and (pointer: fine) {
  .btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
}
.btn-primary:active { transform: translateY(0) scale(0.985); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.btn[disabled] { opacity: 0.55; cursor: default; transform: none; }

/* -------------------------------------------------------------- motion */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

/* -------------------------------------------------------------- phones */
@media (max-width: 480px) {
  .btn {
    width: 100%;
    max-width: 22rem;
    padding: 0.95rem 1.4rem;
  }
  .question,
  .question:lang(ar) {
    max-width: none;
  }
  .card {
    border-radius: 20px;
  }
}

/* Tablets & mid widths: slightly wider reading measure */
@media (min-width: 601px) and (max-width: 900px) {
  :root { --stage-max: min(640px, 100%); }
}

/* Large / wide desktops: keep content centered, don’t stretch type */
@media (min-width: 1200px) {
  :root { --stage-max: 760px; }
}

/* Short viewports (phones landscape, small laptops): keep everything onscreen */
@media (max-height: 560px) {
  .topbar { padding-block: 0.55rem; }
  .stage {
    justify-content: center;
    gap: 0.65rem;
    padding-block: 0.35rem 0.75rem;
  }
  .brand {
    font-size: clamp(2rem, 6vw, 2.6rem);
  }
  :lang(ar) .brand {
    font-size: clamp(2.25rem, 7vw, 3rem);
  }
  .tagline { font-size: 0.88rem; }
  .cat-chip {
    font-size: 0.78rem;
    padding: 0.35rem 0.7rem;
    min-height: 32px;
  }
  .card {
    height: 140px;
    padding: 0.9rem 1.15rem;
  }
  .question {
    font-size: clamp(1.1rem, 3.2vw, 1.4rem);
  }
  .question:lang(ar) {
    font-size: clamp(1.2rem, 3.5vw, 1.55rem);
    line-height: 1.5;
  }
  .btn { padding-block: 0.7rem; }
}

@media (max-height: 420px) {
  .tagline { display: none; }
  .cat-filters { margin-block: -0.15rem; }
  .card { height: 110px; }
}

