/* ============================================================
   LeAlmond — Language gate «نص اللوزة» (Split Almond)
   شاشة اختيار اللغة: بتطلع أول شي، والموقع مخفي وراها لحد ما يختار.
   ============================================================ */

#lang-gate {
  --lg-chalk: #f5ecd9;
  --lg-dim-text: rgba(245, 236, 217, 0.66);
  --lg-gold: #FFC000;
  --lg-green: #98D064;
  --lg-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --lg-door: cubic-bezier(0.76, 0, 0.24, 1);
  /* chalkboard image is 972×548 (1.774) — sized to cover the viewport, continuous across both doors */
  --bgw: max(100vw, 177.4vh);
  --bgh: calc(var(--bgw) / 1.774);
  --bgx: calc((100vw - var(--bgw)) / 2);
  --bgy: calc((100vh - var(--bgh)) / 2);

  position: fixed;
  inset: 0;
  z-index: 2147483000;
  overflow: hidden;
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, sans-serif;
  color: var(--lg-chalk);
  -webkit-font-smoothing: antialiased;
}
#lang-gate *, #lang-gate *::before, #lang-gate *::after { box-sizing: border-box; }
#lang-gate button { font: inherit; color: inherit; margin: 0; }

/* ---------- the two doors ---------- */
.lg-half {
  --dim: 0.52;
  position: absolute;
  top: 0;
  bottom: 0;
  width: 50%;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  background-color: #1e1a14;
  background-image: var(--lg-bg);
  background-repeat: no-repeat;
  background-size: var(--bgw) var(--bgh);
  transition: transform 1s var(--lg-door);
  will-change: transform;
}
.lg-half::before {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(12, 10, 8, var(--dim));
  transition: background 0.45s ease;
}
.lg-half-en { left: 0;  background-position: var(--bgx) var(--bgy); }
.lg-half-ar { right: 0; background-position: calc(var(--bgx) - 50vw) var(--bgy); }
.lg-half:focus-visible { outline: 2px solid var(--lg-gold); outline-offset: -10px; }

.lg-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 16px;
  padding: 150px 6vw 110px;
  text-align: center;
}
.lg-inner > * { max-width: 440px; }

.lg-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  color: var(--lg-green);
}
.lg-half-ar .lg-label { font-size: 14px; letter-spacing: 0; }

.lg-word {
  font-family: 'Aref Ruqaa', serif;
  font-weight: 700;
  font-size: clamp(64px, 8.4vw, 128px);
  line-height: 1.1;
  color: var(--lg-chalk);
  transition: color 0.35s ease, transform 0.45s var(--lg-ease);
}
.lg-half-en .lg-word { font-size: clamp(56px, 7vw, 108px); }

.lg-sub {
  font-size: 19px;
  line-height: 1.6;
  color: rgba(245, 236, 217, 0.82);
}

.lg-example {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 14px 18px;
  border: 1px dashed rgba(245, 236, 217, 0.28);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
  font-size: 17px;
  line-height: 1.7;
}
.lg-example small {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(245, 236, 217, 0.55);
}
.lg-example b { color: var(--lg-green); font-weight: 600; }

.lg-cta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 14px 28px;
  border-radius: 999px;
  border: 1px solid rgba(245, 236, 217, 0.38);
  font-size: 17px;
  font-weight: 600;
  transition: background 0.35s ease, color 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease;
}
.lg-cta svg { width: 18px; height: 18px; }

/* ---------- header, seam, almond, close, footer ---------- */
.lg-head {
  position: absolute;
  top: 40px;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  pointer-events: none;
}
.lg-brand { font-size: 12px; letter-spacing: 0.36em; color: rgba(245, 236, 217, 0.55); }
.lg-title {
  margin: 0;
  font-family: 'Aref Ruqaa', serif;
  font-weight: 700;
  font-size: clamp(30px, 3.4vw, 48px);
  line-height: 1.3;
  color: var(--lg-chalk);
}
.lg-title-en { margin: 0; font-size: 16px; color: var(--lg-dim-text); }

.lg-seam {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 20%;
  bottom: 12%;
  width: 1px;
  transform: translateX(-50%);
  background: linear-gradient(to bottom, transparent, rgba(245, 236, 217, 0.28) 25%, rgba(245, 236, 217, 0.28) 75%, transparent);
  pointer-events: none;
}

.lg-almond {
  --gap: 0px;
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 50%;
  display: flex;
  gap: var(--gap);
  padding: 14px 12px;
  border-radius: 48px;
  background: radial-gradient(closest-side, rgba(20, 17, 13, 0.95), rgba(20, 17, 13, 0.75) 70%, rgba(20, 17, 13, 0));
  transform: translate(-50%, -50%);
  pointer-events: none;
  direction: ltr;
  transition: gap 0.5s var(--lg-ease);
}
.lg-h {
  display: block;
  width: 40px;
  height: 121px;
  overflow: hidden;
  transition: transform 0.5s var(--lg-ease), filter 0.35s ease;
}
.lg-h img { display: block; width: 80px; height: 121px; max-width: none; }
.lg-h-l { transform-origin: 100% 50%; }
.lg-h-r { transform-origin: 0% 50%; }
.lg-h-r img { margin-left: -40px; }

.lg-x {
  position: absolute;
  z-index: 5;
  top: 22px;
  right: 22px;
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid rgba(245, 236, 217, 0.22);
  background: rgba(20, 17, 13, 0.55);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.lg-x:hover { border-color: rgba(245, 236, 217, 0.5); background: rgba(20, 17, 13, 0.8); }
.lg-x:focus-visible { outline: 2px solid var(--lg-gold); outline-offset: 3px; }
.lg-x svg { width: 18px; height: 18px; }

.lg-foot {
  position: absolute;
  z-index: 3;
  bottom: 26px;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(245, 236, 217, 0.55);
  pointer-events: none;
}
.lg-foot svg { width: 15px; height: 15px; }

#lang-gate svg.lg-ic { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- hover / focus: spotlight on one door ---------- */
#lang-gate[data-active="ar"] .lg-half-ar,
#lang-gate[data-active="en"] .lg-half-en { --dim: 0.28; }
#lang-gate[data-active="ar"] .lg-half-en,
#lang-gate[data-active="en"] .lg-half-ar { --dim: 0.8; }
#lang-gate[data-active="ar"] .lg-half-en .lg-inner,
#lang-gate[data-active="en"] .lg-half-ar .lg-inner { opacity: 0.45; }
.lg-inner { transition: opacity 0.4s ease; }
#lang-gate[data-active="ar"] .lg-half-ar .lg-word,
#lang-gate[data-active="en"] .lg-half-en .lg-word { color: var(--lg-gold); transform: scale(1.04); }
#lang-gate[data-active="ar"] .lg-half-ar .lg-cta,
#lang-gate[data-active="en"] .lg-half-en .lg-cta {
  background: var(--lg-gold);
  border-color: var(--lg-gold);
  color: #14110d;
  box-shadow: 0 10px 28px -10px rgba(255, 192, 0, 0.7);
}
#lang-gate[data-active] .lg-almond { --gap: 16px; }
#lang-gate[data-active="en"] .lg-h-l { transform: rotate(-9deg); filter: drop-shadow(0 0 10px rgba(255, 192, 0, 0.75)); }
#lang-gate[data-active="ar"] .lg-h-r { transform: rotate(9deg);  filter: drop-shadow(0 0 10px rgba(255, 192, 0, 0.75)); }

/* ---------- entrance ---------- */
@keyframes lgAlmondIn {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.3) rotate(-14deg); }
  60%  { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(0); }
}
@keyframes lgSeamIn { from { transform: translateX(-50%) scaleY(0); opacity: 0; } to { transform: translateX(-50%) scaleY(1); opacity: 1; } }
@keyframes lgFadeDown { from { opacity: 0; transform: translateY(-14px); } to { opacity: 1; transform: none; } }
@keyframes lgFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes lgFromSeamL { from { opacity: 0; transform: translateX(46px); } to { opacity: 1; transform: none; } }
@keyframes lgFromSeamR { from { opacity: 0; transform: translateX(-46px); } to { opacity: 1; transform: none; } }
@keyframes lgFromSeamUp { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }
@keyframes lgFromSeamDown { from { opacity: 0; transform: translateY(-30px); } to { opacity: 1; transform: none; } }
@keyframes lgBreathe {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 192, 0, 0)); }
  50%      { filter: drop-shadow(0 0 12px rgba(255, 192, 0, 0.35)); }
}

#lang-gate.is-enter .lg-almond { animation: lgAlmondIn 0.8s 0.1s var(--lg-ease) both; }
#lang-gate.is-enter .lg-seam   { animation: lgSeamIn 0.7s 0.55s var(--lg-ease) both; }
#lang-gate.is-enter .lg-head   { animation: lgFadeDown 0.7s 0.95s var(--lg-ease) both; }
#lang-gate.is-enter .lg-x,
#lang-gate.is-enter .lg-foot   { animation: lgFade 0.6s 1.5s ease both; }
#lang-gate.is-enter .lg-half-en .lg-inner > * { animation: lgFromSeamL 0.75s var(--lg-ease) both; }
#lang-gate.is-enter .lg-half-ar .lg-inner > * { animation: lgFromSeamR 0.75s var(--lg-ease) both; }
#lang-gate.is-enter .lg-inner > :nth-child(1) { animation-delay: 0.70s; }
#lang-gate.is-enter .lg-inner > :nth-child(2) { animation-delay: 0.78s; }
#lang-gate.is-enter .lg-inner > :nth-child(3) { animation-delay: 0.86s; }
#lang-gate.is-enter .lg-inner > :nth-child(4) { animation-delay: 0.94s; }
#lang-gate.is-enter .lg-inner > :nth-child(5) { animation-delay: 1.02s; }
#lang-gate.is-idle .lg-h { animation: lgBreathe 3.2s ease-in-out infinite; }
#lang-gate.is-idle[data-active] .lg-h { animation: none; }

/* ---------- exit: the doors open and reveal the site ---------- */
#lang-gate.is-leaving { pointer-events: none; }
#lang-gate.is-leaving .lg-inner,
#lang-gate.is-leaving .lg-head,
#lang-gate.is-leaving .lg-foot,
#lang-gate.is-leaving .lg-x { opacity: 0 !important; transition: opacity 0.3s ease; animation: none; }
#lang-gate.is-leaving .lg-almond { --gap: 0px; }
#lang-gate.is-leaving .lg-h { transform: none; filter: drop-shadow(0 0 16px rgba(255, 192, 0, 0.9)); animation: none; }
#lang-gate.is-opening .lg-half-en { transform: translateX(-101%); }
#lang-gate.is-opening .lg-half-ar { transform: translateX(101%); }
#lang-gate.is-opening .lg-almond { opacity: 0; transform: translate(-50%, -50%) scale(1.7); transition: opacity 0.55s ease, transform 0.7s var(--lg-ease); animation: none; }
#lang-gate.is-opening .lg-seam { opacity: 0; transition: opacity 0.3s ease; animation: none; }
#lang-gate.is-opening .lg-half::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 60px;
  pointer-events: none;
}
#lang-gate.is-opening .lg-half-en::after { right: -60px; background: linear-gradient(to right, rgba(0, 0, 0, 0.45), transparent); }
#lang-gate.is-opening .lg-half-ar::after { left: -60px;  background: linear-gradient(to left,  rgba(0, 0, 0, 0.45), transparent); }

/* arriving on the other-language page: doors start closed, content hidden, then open */
#lang-gate.is-reveal .lg-inner,
#lang-gate.is-reveal .lg-head,
#lang-gate.is-reveal .lg-foot,
#lang-gate.is-reveal .lg-x { opacity: 0; }
#lang-gate.is-reveal .lg-h { filter: drop-shadow(0 0 16px rgba(255, 192, 0, 0.9)); }

/* ---------- phones & narrow screens: doors stack, Arabic on top ---------- */
@media (max-width: 820px) {
  .lg-half { left: 0; right: 0; width: auto; height: 50%; }
  .lg-half-ar { top: 0;    bottom: auto; background-position: var(--bgx) var(--bgy); }
  .lg-half-en { top: auto; bottom: 0;    background-position: var(--bgx) calc(var(--bgy) - 50vh); }
  .lg-inner { gap: 8px; padding: 22px 26px; }
  .lg-half-ar .lg-inner { justify-content: flex-end; padding-bottom: 58px; }
  .lg-half-en .lg-inner { justify-content: flex-start; padding-top: 60px; }
  .lg-inner > * { max-width: 360px; }
  .lg-head { top: 20px; gap: 2px; }
  .lg-title { font-size: 28px; }
  .lg-title-en { font-size: 13px; }
  .lg-brand { font-size: 10px; }
  .lg-word { font-size: 58px; }
  .lg-half-en .lg-word { font-size: 50px; }
  .lg-sub { font-size: 15px; }
  .lg-example { padding: 9px 14px; font-size: 14px; line-height: 1.6; }
  .lg-example small { display: none; }
  .lg-cta { padding: 11px 22px; font-size: 15px; margin-top: 4px; }
  .lg-seam { display: none; }
  .lg-almond { padding: 10px 9px; }
  .lg-h { width: 28px; height: 85px; }
  .lg-h img { width: 56px; height: 85px; }
  .lg-h-r img { margin-left: -28px; }
  .lg-x { top: 12px; right: 12px; }
  .lg-foot { bottom: 16px; font-size: 11.5px; flex-direction: column; gap: 2px; }
  .lg-foot svg, .lg-foot .lg-dot { display: none; }
  #lang-gate.is-enter .lg-half-ar .lg-inner > * { animation-name: lgFromSeamDown; }
  #lang-gate.is-enter .lg-half-en .lg-inner > * { animation-name: lgFromSeamUp; }
  #lang-gate.is-opening .lg-half-ar { transform: translateY(-101%); }
  #lang-gate.is-opening .lg-half-en { transform: translateY(101%); }
  #lang-gate.is-opening .lg-half-en::after,
  #lang-gate.is-opening .lg-half-ar::after { display: none; }
}
@media (max-width: 820px) and (max-height: 700px) {
  .lg-example { display: none; }
}

/* ---------- reduced motion: no travel, just a quick fade ---------- */
@media (prefers-reduced-motion: reduce) {
  #lang-gate *, #lang-gate *::before, #lang-gate *::after { animation: none !important; transition: none !important; }
  #lang-gate.is-opening { opacity: 0; transition: opacity 0.25s ease !important; }
  #lang-gate.is-opening .lg-half { transform: none !important; }
}
