/* =====================================================================
   Tharwa Project Switcher — overlay stylesheet
   ---------------------------------------------------------------------
   ALL selectors are prefixed ".tsw-" and everything lives inside the
   #tsw-root container. Zero global leakage: no bare-tag selectors, no
   resets applied to the host app. The overlay is position:fixed at an
   extreme z-index so it NEVER causes layout shift on the underlying SPA.
   Visual language per SWITCHER-SPEC.md.
   ===================================================================== */

/* --- Arabic display face (same file the app ships) ------------------- */
@font-face {
  font-family: "29LT Kaff";
  src: url("assets/29LT-Kaff-Regular-BIUndwwv.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* --- Design tokens (scoped to the root, cannot leak) ---------------- */
#tsw-root {
  --tsw-chrome: rgba(17, 16, 24, 0.92);      /* #111018 @ .92 */
  --tsw-chrome-solid: #111018;
  --tsw-ink: #ffffff;
  --tsw-ink-60: rgba(255, 255, 255, 0.6);
  --tsw-ink-40: rgba(255, 255, 255, 0.4);
  --tsw-surface: #ffffff;
  --tsw-surface-ink: #14131b;
  --tsw-surface-ink-60: rgba(20, 19, 27, 0.62);
  --tsw-accent: #ff6347;                      /* tomato */
  --tsw-green: #80d20d;                        /* active */
  --tsw-amber: #c4692a;                        /* coming-soon */
  --tsw-card-radius: 16px;
  --tsw-card-shadow: 0 1px 2px rgba(10, 9, 16, 0.08),
                     0 12px 32px rgba(10, 9, 16, 0.18);
  --tsw-ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --tsw-dur: 340ms;
  --tsw-focus: 0 0 0 3px rgba(255, 99, 71, 0.9), 0 0 0 5px rgba(17, 16, 24, 0.9);

  /* Reset the container's own inherited environment without touching
     the host app. Only descendants of #tsw-root are affected. */
  position: fixed;
  inset: 0;
  z-index: 2147483000;
  margin: 0;
  padding: 0;
  color: var(--tsw-ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial,
    sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;

  /* Hidden by default; JS toggles .tsw-open */
  visibility: hidden;
  pointer-events: none;
}

#tsw-root.tsw-open {
  visibility: visible;
  pointer-events: auto;
}

/* A CLOSED root must hide its ENTIRE subtree. An active screen sets
   visibility:visible/pointer-events:auto, and because CSS `visibility` on a
   child overrides an ancestor's `visibility:hidden`, a screen left active at
   close time would re-show itself and keep intercepting clicks over the map.
   Force every screen + scrim hidden and inert whenever the root isn't open. */
#tsw-root:not(.tsw-open) .tsw-screen,
#tsw-root:not(.tsw-open) .tsw-scrim {
  visibility: hidden !important;
  pointer-events: none !important;
  opacity: 0 !important;
}

/* Arabic language: swap the display face for the whole overlay. */
#tsw-root[dir="rtl"] {
  font-family: "29LT Kaff", "Inter", system-ui, -apple-system, "Segoe UI",
    Roboto, Arial, sans-serif;
}

/* Universal box-sizing, scoped strictly under the root. */
#tsw-root *,
#tsw-root *::before,
#tsw-root *::after {
  box-sizing: border-box;
}

/* --- Scrim ---------------------------------------------------------- */
.tsw-scrim {
  position: absolute;
  inset: 0;
  background: var(--tsw-chrome);
  -webkit-backdrop-filter: blur(18px) saturate(120%);
  backdrop-filter: blur(18px) saturate(120%);
  opacity: 0;
  transition: opacity var(--tsw-dur) var(--tsw-ease);
}

#tsw-root.tsw-open .tsw-scrim {
  opacity: 1;
}

/* --- Screen stack --------------------------------------------------- */
.tsw-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  transform: scale(0.985);
  pointer-events: none;
  /* visibility:hidden removes inactive screens from the tab order and the
     a11y tree; the delay lets the fade-out animate before it hides. */
  visibility: hidden;
  transition: opacity var(--tsw-dur) var(--tsw-ease),
    transform var(--tsw-dur) var(--tsw-ease),
    visibility 0s linear var(--tsw-dur);
}

.tsw-screen.tsw-screen--active {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
  visibility: visible;
  transition: opacity var(--tsw-dur) var(--tsw-ease),
    transform var(--tsw-dur) var(--tsw-ease), visibility 0s;
}

/* When a screen is leaving upward in the stack (selector -> landing) it
   scales slightly the other way for depth. Applied via .tsw-screen--back. */
.tsw-screen.tsw-screen--back {
  opacity: 0;
  transform: scale(1.015);
  pointer-events: none;
}

/* =====================================================================
   SELECTOR SCREEN
   ===================================================================== */
.tsw-selector {
  align-items: center;
}

.tsw-shell {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(20px, 5vw, 56px) clamp(16px, 4vw, 40px) 64px;
}

.tsw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: clamp(20px, 4vw, 36px);
}

.tsw-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 32px;
}

.tsw-brand-logo {
  height: 22px;
  width: auto;
  display: block;
}

.tsw-title {
  font-size: clamp(1.35rem, 3.4vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--tsw-ink);
}

.tsw-header .tsw-title {
  text-align: end;
}

/* Close (X) button — appears top-end of the selector */
.tsw-close {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.08);
  color: var(--tsw-ink);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
  transition: background var(--tsw-dur) var(--tsw-ease),
    transform var(--tsw-dur) var(--tsw-ease);
}

.tsw-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.tsw-close:active {
  transform: scale(0.94);
}

.tsw-close svg {
  width: 18px;
  height: 18px;
}

/* --- Card grid ------------------------------------------------------ */
.tsw-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: clamp(16px, 2.4vw, 26px);
}

/* --- Card ----------------------------------------------------------- */
.tsw-card {
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: start;
  background: var(--tsw-surface);
  color: var(--tsw-surface-ink);
  border: 0;
  border-radius: var(--tsw-card-radius);
  box-shadow: var(--tsw-card-shadow);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  font: inherit;
  opacity: 0;
  transform: translateY(14px) scale(0.985);
  transition: transform var(--tsw-dur) var(--tsw-ease),
    box-shadow var(--tsw-dur) var(--tsw-ease),
    opacity var(--tsw-dur) var(--tsw-ease);
}

/* Staggered reveal driven by --tsw-i index set inline in JS. */
#tsw-root.tsw-open .tsw-selector.tsw-screen--active .tsw-card {
  opacity: 1;
  transform: translateY(0) scale(1);
  transition-delay: calc(var(--tsw-i, 0) * 55ms);
}

.tsw-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 2px 4px rgba(10, 9, 16, 0.1),
    0 22px 48px rgba(10, 9, 16, 0.26);
}

.tsw-card:hover .tsw-card-hero img {
  transform: scale(1.05);
}

.tsw-card-hero {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #e9e8ee;
  overflow: hidden;
}

.tsw-card-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 600ms var(--tsw-ease);
}

/* logo badge floating over the hero, bottom-start */
.tsw-card-logo {
  position: absolute;
  inset-inline-start: 14px;
  bottom: 14px;
  height: 30px;
  max-width: 62%;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(10, 9, 16, 0.22);
  display: flex;
  align-items: center;
}

.tsw-card-logo img {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  display: block;
}

.tsw-card-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 18px 20px;
  flex: 1;
}

.tsw-card-namerow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.tsw-card-name {
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--tsw-surface-ink);
}

.tsw-card-arname {
  font-family: "29LT Kaff", "Inter", sans-serif;
  font-size: 1rem;
  color: var(--tsw-surface-ink-60);
  margin: 0;
  white-space: nowrap;
}

.tsw-card-metarow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tsw-city {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.9rem;
  color: var(--tsw-surface-ink-60);
}

.tsw-city svg {
  width: 14px;
  height: 14px;
  flex: none;
  opacity: 0.7;
}

/* --- Status chip ---------------------------------------------------- */
.tsw-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  padding: 5px 10px 5px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.tsw-chip::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.tsw-chip--active {
  color: #4d7f08;
  background: rgba(128, 210, 13, 0.16);
}

.tsw-chip--soon {
  color: var(--tsw-amber);
  background: rgba(196, 105, 42, 0.14);
}

.tsw-card-desc {
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--tsw-surface-ink-60);
  margin: 0;
  /* clamp to keep card heights even */
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tsw-stat {
  font-size: 0.9rem;
  color: var(--tsw-surface-ink);
  margin: 2px 0 0;
  font-weight: 500;
}

.tsw-stat b {
  font-weight: 700;
}

.tsw-stat--muted {
  color: var(--tsw-surface-ink-60);
}

/* --- Launch (dark pill) --------------------------------------------- */
.tsw-launch {
  margin-top: auto;
  align-self: flex-start;
  appearance: none;
  border: 0;
  background: var(--tsw-chrome-solid);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 0.94rem;
  padding: 11px 20px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: transform var(--tsw-dur) var(--tsw-ease),
    box-shadow var(--tsw-dur) var(--tsw-ease),
    background var(--tsw-dur) var(--tsw-ease);
}

.tsw-launch:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(17, 16, 24, 0.32);
}

.tsw-launch:active {
  transform: translateY(0);
}

.tsw-launch svg {
  width: 15px;
  height: 15px;
}

.tsw-launch--disabled,
.tsw-launch[disabled] {
  background: #d9d7e0;
  color: #8a8794;
  cursor: not-allowed;
  pointer-events: none;
}

.tsw-launch--current {
  background: #fff;
  color: var(--tsw-surface-ink);
  border: 1.5px solid rgba(20, 19, 27, 0.16);
  padding: 9.5px 18px;
}

/* --- Current ribbon ------------------------------------------------- */
.tsw-ribbon {
  position: absolute;
  inset-inline-end: 14px;
  top: 14px;
  z-index: 2;
  background: var(--tsw-accent);
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 5px 11px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(255, 99, 71, 0.4);
}

/* Coming-soon cards are slightly dimmed */
.tsw-card--soon .tsw-card-hero img {
  filter: saturate(0.72) brightness(0.98);
}

/* =====================================================================
   LANDING SCREEN (full-bleed)
   ===================================================================== */
.tsw-landing {
  position: absolute;
  inset: 0;
  color: #fff;
  overflow: hidden;
}

.tsw-landing-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transform: scale(1.04);
  transition: transform 900ms var(--tsw-ease);
}

.tsw-landing.tsw-screen--active .tsw-landing-bg {
  transform: scale(1);
}

.tsw-landing-veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(
      to top,
      rgba(10, 9, 16, 0.94) 0%,
      rgba(10, 9, 16, 0.55) 42%,
      rgba(10, 9, 16, 0.3) 70%,
      rgba(10, 9, 16, 0.5) 100%
    );
}

.tsw-landing-inner {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 40px) clamp(18px, 5vw, 56px)
    clamp(32px, 6vw, 64px);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.tsw-landing-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: auto;
}

.tsw-back {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex: none;
  transition: background var(--tsw-dur) var(--tsw-ease),
    transform var(--tsw-dur) var(--tsw-ease);
}

.tsw-back:hover {
  background: rgba(255, 255, 255, 0.22);
}

.tsw-back:active {
  transform: scale(0.94);
}

.tsw-back svg {
  width: 20px;
  height: 20px;
}

/* Back arrow flips in RTL */
#tsw-root[dir="rtl"] .tsw-back svg {
  transform: scaleX(-1);
}

.tsw-landing-content {
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 8px;
}

.tsw-landing-logo {
  height: 46px;
  max-width: 220px;
  width: auto;
  object-fit: contain;
  object-position: left center;
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.94);
  padding: 9px 14px;
  border-radius: 12px;
}

#tsw-root[dir="rtl"] .tsw-landing-logo {
  object-position: right center;
  align-self: flex-end;
}

.tsw-landing-chip-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tsw-landing-titles {
  display: flex;
  align-items: baseline;
  gap: 16px;
  flex-wrap: wrap;
}

.tsw-landing-title {
  font-size: clamp(2rem, 6vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.02;
  margin: 0;
}

.tsw-landing-artitle {
  font-family: "29LT Kaff", "Inter", sans-serif;
  font-size: clamp(1.2rem, 3.4vw, 1.9rem);
  color: rgba(255, 255, 255, 0.72);
  margin: 0;
}

.tsw-landing-loc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.78);
}

.tsw-landing-loc svg {
  width: 16px;
  height: 16px;
  opacity: 0.85;
}

.tsw-landing-desc {
  font-size: clamp(1rem, 2.2vw, 1.12rem);
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.82);
  margin: 0;
  max-width: 60ch;
}

.tsw-cta-row {
  margin-top: 18px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.tsw-cta {
  appearance: none;
  border: 0;
  background: var(--tsw-accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  font-size: 1.02rem;
  padding: 15px 30px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 30px rgba(255, 99, 71, 0.36);
  transition: transform var(--tsw-dur) var(--tsw-ease),
    box-shadow var(--tsw-dur) var(--tsw-ease),
    background var(--tsw-dur) var(--tsw-ease);
}

.tsw-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 38px rgba(255, 99, 71, 0.46);
}

.tsw-cta:active {
  transform: translateY(0);
}

.tsw-cta svg {
  width: 18px;
  height: 18px;
}

#tsw-root[dir="rtl"] .tsw-cta svg {
  transform: scaleX(-1);
}

.tsw-cta--current {
  background: rgba(255, 255, 255, 0.96);
  color: var(--tsw-surface-ink);
  box-shadow: 0 10px 30px rgba(10, 9, 16, 0.4);
}

.tsw-cta--disabled,
.tsw-cta[disabled] {
  background: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.55);
  cursor: not-allowed;
  box-shadow: none;
  pointer-events: none;
}

/* =====================================================================
   TRANSITION SCREEN (covered loader)
   ===================================================================== */
.tsw-transition {
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
}

.tsw-transition-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  transform: scale(1.06);
  animation: tsw-slowzoom 3s var(--tsw-ease) forwards;
}

@keyframes tsw-slowzoom {
  to {
    transform: scale(1);
  }
}

.tsw-transition-veil {
  position: absolute;
  inset: 0;
  background: rgba(10, 9, 16, 0.72);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.tsw-transition-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding: 24px;
  text-align: center;
}

.tsw-transition-logo {
  height: 30px;
  width: auto;
  opacity: 0.96;
  animation: tsw-pulse 1.8s var(--tsw-ease) infinite;
}

@keyframes tsw-pulse {
  0%,
  100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

.tsw-transition-label {
  font-size: 1.05rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin: 0;
}

.tsw-progress {
  position: relative;
  width: min(240px, 60vw);
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}

.tsw-progress::before {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: 999px;
  background: var(--tsw-accent);
  animation: tsw-indeterminate 1.15s var(--tsw-ease) infinite;
}

@keyframes tsw-indeterminate {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(320%);
  }
}

/* =====================================================================
   ACCESSIBILITY — focus rings
   ===================================================================== */
#tsw-root :focus {
  outline: none;
}

#tsw-root :focus-visible {
  outline: none;
  box-shadow: var(--tsw-focus);
}

.tsw-card:focus-visible {
  box-shadow: var(--tsw-focus), var(--tsw-card-shadow);
}

/* Screen-reader-only helper */
.tsw-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 640px) {
  .tsw-grid {
    grid-template-columns: 1fr;
  }

  .tsw-header {
    align-items: flex-start;
  }

  .tsw-cta {
    width: 100%;
    justify-content: center;
  }

  .tsw-landing-titles {
    gap: 8px;
  }
}

/* =====================================================================
   REDUCED MOTION — opacity-only, no transform/scale animation
   ===================================================================== */
@media (prefers-reduced-motion: reduce) {
  #tsw-root *,
  #tsw-root *::before,
  #tsw-root *::after {
    transition-duration: 160ms !important;
    transition-property: opacity !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }

  .tsw-screen,
  .tsw-screen.tsw-screen--back,
  .tsw-card,
  #tsw-root.tsw-open .tsw-selector.tsw-screen--active .tsw-card,
  .tsw-landing-bg,
  .tsw-transition-bg {
    transform: none !important;
  }

  /* keep an indeterminate bar readable without motion */
  .tsw-progress::before {
    animation: tsw-fade 1.2s ease-in-out infinite !important;
    width: 100% !important;
  }

  @keyframes tsw-fade {
    0%,
    100% {
      opacity: 0.35;
    }
    50% {
      opacity: 0.9;
    }
  }
}
