/* The card. Colors come from tokens.css.
   Every size is in cqw (1cqw = 1% of the card's width) so the card scales as one piece.
   Design size is 1080 x 1080, so N px in the design = N / 10.8 cqw. */

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: grid;
  place-items: center;
  background: var(--green);
}

.card {
  position: relative;
  width: min(100vw, 100vh, 1080px);
  aspect-ratio: 1;
  overflow: hidden;
  container-type: inline-size;
  font-family: var(--font-sans);
  color: var(--green);
}

/* ---------- sky: 0% to 56% ---------- */

.sky {
  position: absolute;
  inset: 0 0 44cqw 0;
  background: linear-gradient(var(--sky-top), var(--sky-bottom));
}

.brand {
  position: absolute;
  top: 5cqw;
  inset-inline-start: 5cqw;
  display: flex;
  align-items: center;
  gap: 1.2cqw;
  font-size: 2.6cqw;
  font-weight: 400;
  line-height: 1;
}

.brand__logo {
  width: 2.6cqw;
  height: 2.6cqw;
  background: var(--lime);
  border: 0.45cqw solid var(--green);
}

/* The vertical padding gives letters that hang below the line (Arabic و ل ح م)
   room inside the box, so the reveal's clip-path does not cut them off. */
.brand__text { white-space: nowrap; padding-block: 0.35em; }

/* Link to the card in the other language, in the corner opposite the brand.
   It is written in that other language, so it takes that language's font. */
.lang-switch {
  position: absolute;
  top: 4.2cqw;
  inset-inline-end: 5cqw;
  padding: 0.7cqw 1.4cqw;
  border: 0.45cqw solid var(--green);
  font-size: 1.9cqw;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  color: var(--green);
}
.lang-switch:lang(en) { font-family: var(--font-mono); }
.lang-switch:lang(ar) { font-family: "IBM Plex Sans Arabic", sans-serif; font-size: 2.2cqw; }
.lang-switch:hover, .lang-switch:focus-visible { background: var(--lime); outline: none; }
.is-frozen .lang-switch { display: none; } /* screenshots and the video */

.headline {
  position: absolute;
  top: 11.5cqw;
  inset-inline-start: 5cqw;
  margin: 0;
  z-index: 1; /* the clouds drift behind the text, never over it */
  font-family: var(--font-display);
  font-size: 6cqw;
  font-weight: 900;
  line-height: 1.12;
  letter-spacing: -0.035em;
  text-transform: uppercase;
}

.headline__line { display: block; width: fit-content; white-space: nowrap; }

.headline__line--mark {
  margin-top: 0.5cqw;
  margin-inline-start: -1cqw;
  padding: 0 1cqw;
  background: var(--lime);
}

/* clouds: a wide bar with a narrower bar on top */
/* The clouds layer covers the whole sky, so clicks must pass through it
   to the language link underneath. */
.clouds { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }

.cloud {
  position: absolute;
  left: 0;
  height: var(--h);
  width: var(--w);
  background: var(--cloud);
  transform: translateX(var(--x));
}

.cloud::before {
  content: "";
  position: absolute;
  bottom: 100%;
  left: 22%;
  width: 48%;
  height: 100%;
  background: var(--cloud);
}

.cloud--a { --w: 17cqw; --h: 2.4cqw; --x: 6cqw;  top: 36cqw; }
.cloud--b { --w: 11cqw; --h: 1.8cqw; --x: 34cqw; top: 44cqw; }
.cloud--c { --w: 14cqw; --h: 2.1cqw; --x: 46cqw; top: 31cqw; }

/* character: 2x its pixel size at 1080, feet on the grass */
.sprite {
  position: absolute;
  inset-inline-end: 7cqw;
  bottom: -1cqw;
  width: 24.815cqw;   /* 134px sprite x 2 */
  height: 43.333cqw;  /* 234px sprite x 2 */
  z-index: 2;
}

.sprite__frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.sprite__frame--point { visibility: hidden; }

/* ---------- grass: 56% to 58% ---------- */

.grass {
  position: absolute;
  top: 56cqw;
  left: 0;
  right: 0;
  height: 2cqw;
  background: repeating-linear-gradient(90deg,
    var(--lime) 0 2cqw, var(--lime-dark) 2cqw 4cqw);
}

/* ---------- panel: 58% to 100% ---------- */

.panel {
  position: absolute;
  inset: 58cqw 0 0 0;
  background: var(--green);
}

.dialogue {
  position: absolute;
  top: 5cqw;
  left: 6cqw;
  right: 6cqw;
  height: 28cqw;
  padding: 4.2cqw 4cqw 0;
  background: var(--box);
  border: 0.37cqw solid var(--light); /* 4px at 1080 */
}

.dialogue__name {
  position: absolute;
  top: -1.9cqw;
  inset-inline-start: 3cqw;
  padding: 0.7cqw 1.5cqw;
  background: var(--lime);
  color: var(--green);
  font-family: var(--font-label);
  font-size: 2cqw;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.06em;
}

.dialogue__text {
  margin: 0;
  color: var(--light);
  font-size: 2.75cqw;
  font-weight: 500;
  line-height: 1.45;
}

.dialogue__line { display: block; white-space: nowrap; }

.choices {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5cqw;
  margin-top: 2.6cqw;
  font-family: var(--font-label);
  font-size: 2.5cqw;
  font-weight: 700;
  line-height: 1;
}

.choice {
  display: flex;
  align-items: center;
  gap: 1.2cqw;
  padding-block: 0.9cqw;
  padding-inline: 0 1.4cqw;
  color: var(--muted);
  text-decoration: none;
  outline: none;
}

.cursor {
  width: 2.2cqw;
  font-size: 1.9cqw;
  color: var(--lime);
  visibility: hidden;
}

.choice__label { padding: 0.5cqw 1cqw; margin: -0.5cqw 0; }

.choice.is-active { color: var(--lime); }
.choice.is-active .cursor { visibility: visible; }
.choice.is-selected .choice__label { background: var(--lime); color: var(--green); }
.choice:focus-visible .choice__label { outline: 0.25cqw solid var(--light); outline-offset: 0.3cqw; }

.footer {
  position: absolute;
  inset-inline-start: 6cqw;
  bottom: 3.2cqw;
  margin: 0;
  color: var(--light);
  opacity: 0.6;
  font-family: var(--font-label);
  font-size: 1.7cqw;
  line-height: 1;
}

/* ---------- Arabic, right to left ----------
   The layout above mirrors by itself (headline on the right, character on
   the left). These are the sizes Arabic letters need. */

:lang(ar).brand { font-size: 2.9cqw; font-weight: 500; }
[dir="rtl"] .clouds { transform: scaleX(-1); } /* mirrored places, drifting the other way */

:lang(ar).headline { font-size: 6.6cqw; line-height: 1.5; }
:lang(ar).headline__line--mark { margin-top: 1cqw; line-height: 1.35; }
:lang(ar).dialogue__name { font-size: 2.4cqw; padding: 0.6cqw 1.8cqw 0.9cqw; }
:lang(ar).dialogue__text { font-size: 3cqw; line-height: 1.55; }
:lang(ar).choices { margin-top: 2cqw; font-size: 2.8cqw; }
:lang(ar).footer { font-size: 1.9cqw; }
:lang(ar).cursor { font-size: 2.2cqw; }

/* ---------- motion (independent of the 7-second loop) ---------- */

.dialogue__rest { visibility: hidden; }

/* read by screen readers, not shown */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* sprite: swap frames once per second, with a 2px bob, in hard steps */
.sprite { animation: sprite-bob 1s steps(1, end) infinite; }
.sprite__frame--idle { animation: sprite-swap 2s steps(1, end) infinite; }
.sprite__frame--point { animation: sprite-swap 2s steps(1, end) -1s infinite; }

@keyframes sprite-swap {
  0% { visibility: visible; }
  50% { visibility: hidden; }
}

@keyframes sprite-bob {
  0% { transform: translateY(0); }
  50% { transform: translateY(-0.19cqw); }
}

/* clouds: drift right and wrap; negative delays start each one mid-way */
.cloud { animation: cloud-drift var(--t) linear var(--d) infinite; }
.cloud--a { --t: 90s;  --d: -19.5s; }
.cloud--b { --t: 130s; --d: -58.5s; }
.cloud--c { --t: 110s; --d: -60.5s; }

@keyframes cloud-drift {
  from { transform: translateX(-20cqw); }
  to { transform: translateX(100cqw); }
}

/* frozen frame or reduced motion: no sprite swap, no drift */
.is-still .sprite,
.is-still .sprite__frame,
.is-still .cloud { animation: none; }

@media (prefers-reduced-motion: reduce) {
  .sprite, .sprite__frame, .cloud { animation: none; }
}
