/* ================================================================
   TDI — homepage prototype
   Mobile-first, responsive, RTL-aware
   ================================================================ */

:root {
  --bg-0: #020617;
  --bg-1: #05112b;
  --bg-2: #0a1f45;
  --fg: #e9f1ff;
  --fg-dim: #9ab4d6;
  --accent: #6fc3ff;
  --accent-2: #c9a96a;
  --panel: rgba(6, 18, 42, 0.55);
  --border: rgba(120, 180, 240, 0.18);
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Cormorant Garamond", "Frank Ruhl Libre", Georgia, serif;
  --ease: cubic-bezier(.2,.7,.2,1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: radial-gradient(ellipse at center, var(--bg-2) 0%, var(--bg-1) 40%, var(--bg-0) 100%);
  color: var(--fg);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

html[dir="rtl"] body { font-family: "Frank Ruhl Libre", var(--font-sans); }

/* ================================================================
   STARFIELD
   ================================================================ */
.stars, .stars--far {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #fff, transparent),
    radial-gradient(1px 1px at 70% 20%, #fff, transparent),
    radial-gradient(1px 1px at 40% 70%, #fff, transparent),
    radial-gradient(2px 2px at 85% 55%, #fff, transparent),
    radial-gradient(1px 1px at 15% 85%, #fff, transparent),
    radial-gradient(1px 1px at 55% 45%, #fff, transparent),
    radial-gradient(1px 1px at 92% 88%, #fff, transparent),
    radial-gradient(1px 1px at 33% 12%, #fff, transparent);
  background-size: 600px 600px;
  opacity: .65;
  animation: starDrift 120s linear infinite;
}
.stars--far {
  background-size: 900px 900px;
  opacity: .35;
  animation-duration: 240s;
  animation-direction: reverse;
}
@keyframes starDrift {
  from { background-position: 0 0; }
  to   { background-position: 600px 600px; }
}

/* ================================================================
   LANGUAGE PICKER
   ================================================================ */
.lang-picker {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 5vw, 3rem);
  z-index: 20;
  animation: fadeIn .8s var(--ease);
}
.lang-picker.is-hidden {
  animation: fadeOut .6s var(--ease) forwards;
  pointer-events: none;
}

.lang-picker__inner {
  width: min(560px, 100%);
  text-align: center;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: clamp(1.5rem, 5vw, 2.75rem);
  box-shadow: 0 20px 60px -20px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,.02) inset;
}

.lang-picker__title {
  font-family: var(--font-serif);
  font-size: clamp(3rem, 10vw, 5rem);
  letter-spacing: .15em;
  margin: 0;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(111,195,255,.35);
}
.lang-picker__subtitle {
  font-size: clamp(.75rem, 2.5vw, .95rem);
  letter-spacing: .25em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin: .25rem 0 1.75rem;
}
.lang-picker__prompt {
  font-size: clamp(.85rem, 2.5vw, 1rem);
  color: var(--fg-dim);
  margin: 0 0 1.5rem;
}

.lang-picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: .75rem;
}

.lang-btn {
  appearance: none;
  background: rgba(255,255,255,.04);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: .85rem 1rem;
  font: inherit;
  font-size: 1rem;
  cursor: pointer;
  transition: transform .2s var(--ease), background .2s var(--ease), border-color .2s var(--ease);
}
.lang-btn:hover,
.lang-btn:focus-visible {
  background: rgba(111,195,255,.12);
  border-color: var(--accent);
  transform: translateY(-2px);
  outline: none;
}
.lang-btn:active { transform: translateY(0); }

/* ================================================================
   STAGE
   ================================================================ */
.stage {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.earth-scene {
  position: relative;
  flex: 1 1 auto;
  min-height: 42vh;
  display: grid;
  place-items: center;
  pointer-events: none;
  overflow: visible;
  container-type: size;
  container-name: earth;
}

.earth {
  width:  min(88cqmin, 620px);
  height: min(88cqmin, 620px);
  max-width: 92%;
  max-height: 92%;
  aspect-ratio: 1;
  position: relative;
  transform-origin: center;
  transform: scale(.02);
  opacity: 0;
  will-change: transform, opacity;
  filter: drop-shadow(0 0 80px rgba(111,195,255,.32));
}
.earth-canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.earth--svg-fallback { filter: drop-shadow(0 0 100px rgba(111,195,255,.45)); }

/* Approach animation triggered by JS */
.earth--approach {
  animation: earthApproach 5.5s var(--ease) forwards;
}

@keyframes earthApproach {
  0%   { transform: scale(.015); opacity: 0; filter: drop-shadow(0 0 0 rgba(111,195,255,0)) blur(10px); }
  20%  { opacity: 1; }
  70%  { filter: drop-shadow(0 0 60px rgba(111,195,255,.28)) blur(1px); }
  100% { transform: scale(1); opacity: 1; filter: drop-shadow(0 0 100px rgba(111,195,255,.40)) blur(0); }
}

/* ================================================================
   NARRATION
   ================================================================ */
.narration {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  width: min(760px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2.5rem);
  padding-bottom: clamp(1.5rem, 4vw, 2.5rem);
}

.narration__text {
  background: var(--panel);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: clamp(1.25rem, 4vw, 2rem) clamp(1.25rem, 4vw, 2.25rem);
  max-height: 55vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) transparent;
  opacity: 0;
  transform: translateY(24px);
  transition: opacity 1s var(--ease), transform 1s var(--ease);
}
.narration__text.is-visible { opacity: 1; transform: translateY(0); }
.narration__text::-webkit-scrollbar { width: 6px; }
.narration__text::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }

.narration__text p,
.narration__text ul {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .9s var(--ease), transform .9s var(--ease);
  font-family: var(--font-serif);
  font-size: clamp(1.05rem, 2.4vw, 1.25rem);
  line-height: 1.6;
  margin: 0 0 1rem;
}
.narration__text p.is-visible,
.narration__text ul.is-visible { opacity: 1; transform: translateY(0); }
.narration__text p:last-child,
.narration__text ul:last-child { margin-bottom: 0; }
.narration__text ul { padding-inline-start: 1.25rem; }
.narration__text li { margin-bottom: .4rem; }
.narration__text strong { color: var(--accent); font-weight: 600; }

@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ================================================================
   CONTROLS
   ================================================================ */
.controls {
  position: fixed;
  bottom: clamp(1rem, 3vw, 1.75rem);
  right: clamp(1rem, 3vw, 1.75rem);
  display: flex;
  gap: .6rem;
  z-index: 10;
  opacity: 0;
  transition: opacity 1s var(--ease);
}
.controls.is-visible { opacity: 1; }
html[dir="rtl"] .controls { right: auto; left: clamp(1rem, 3vw, 1.75rem); }

.ctrl-btn {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--fg);
  font-size: 1.2rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform .2s var(--ease), background .2s var(--ease);
}
.ctrl-btn:hover { background: rgba(111,195,255,.15); transform: scale(1.05); }
.ctrl-btn__off { display: none; }
.ctrl-btn.is-muted .ctrl-btn__on  { display: none; }
.ctrl-btn.is-muted .ctrl-btn__off { display: inline; }

/* ================================================================
   RESPONSIVE TWEAKS
   ================================================================ */
.narration__text { max-height: 50vh; }

@media (max-width: 640px) {
  .lang-picker__grid { grid-template-columns: repeat(2, 1fr); }
  .earth-scene { min-height: 45vh; }
  .narration__text { max-height: 46vh; }
}

@media (max-width: 380px) {
  .lang-picker__grid { grid-template-columns: 1fr; }
}

@media (min-width: 1024px) {
  .stage { flex-direction: row; align-items: stretch; }
  .earth-scene {
    flex: 1 1 50%;
    min-width: 0;
    min-height: 100vh;
  }
  .narration {
    flex: 0 0 50%;
    min-width: 0;
    width: auto;
    max-width: 600px;
    margin: 0 auto;
    align-self: center;
    padding: clamp(1rem, 3vw, 2rem);
  }
  .narration__text { max-height: 75vh; }
}

@media (prefers-reduced-motion: reduce) {
  .earth, .earth .continents, .earth .clouds, .stars, .stars--far {
    animation: none !important;
  }
  .earth { transform: scale(1) !important; opacity: 1 !important; }
  .narration__text, .narration__text p, .narration__text ul { opacity: 1 !important; transform: none !important; }
}
