/* Base: reset, typography, app shell (top bar, boot screen), utilities. */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--topbar-height) + 16px);
}

body {
  position: relative;
  margin: 0;
  background-color: var(--paper);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Two soft glows behind the top of every page, as on the main site. */
body::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 900px;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(38rem 26rem at 12% 8%, var(--glow-1), transparent 70%),
    radial-gradient(34rem 24rem at 88% 22%, var(--glow-2), transparent 70%);
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img,
svg {
  max-width: 100%;
}

h1,
h2,
h3,
h4,
h5 {
  margin: 0;
  line-height: var(--lh-tight);
  text-wrap: balance;
  color: var(--ink);
}

/* Big titles use the display face (Kufi in Arabic, Outfit in English). */
.display-title,
.hero-title,
.section-title,
.level-title,
.lesson-title,
.page-title,
.boot-title,
.reference-section-title,
.certificate-name {
  font-family: var(--font-display);
  font-weight: var(--weight-display);
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-display);
}

/* Gradient ink for the one phrase a page is about (the site's name treatment). */
.grad-text {
  background-image: var(--text-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 3px;
}

a:hover {
  color: var(--accent-hover);
}

code,
kbd,
pre {
  font-family: var(--font-mono);
}

:not(pre) > code {
  direction: ltr;
  unicode-bidi: isolate;
  font-size: 0.86em;
  padding: 0.05em 0.38em;
  margin-inline: 0.08em;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--rule);
  color: var(--ink);
  /* Long snippets wrap inside the line instead of widening the page. */
  white-space: normal;
  overflow-wrap: anywhere;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

kbd {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  font-size: 0.78em;
  padding: 0 0.45em;
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink-2);
}

mark {
  background: linear-gradient(transparent 12%, var(--highlight-wash) 12%, var(--highlight-wash) 88%, transparent 88%);
  color: inherit;
  padding: 0 0.12em;
}

strong {
  font-weight: 650;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--r-sm);
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.ltr {
  direction: ltr;
  unicode-bidi: isolate;
}

.num {
  font-variant-numeric: tabular-nums;
}

.skip-link {
  position: absolute;
  inset-inline-start: 12px;
  top: -60px;
  z-index: 100;
  padding: 8px 14px;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: var(--r-sm);
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

/* Default for every line icon from dom.icon(); contexts like `.btn svg` set their own size. */
.icon {
  width: 1.25em;
  height: 1.25em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  min-height: var(--topbar-height);
  padding-block: 8px;
  /* The bar spans the screen, but its contents line up with the page column below it. */
  padding-inline: max(var(--gutter), calc((100% - var(--page-width)) / 2 + var(--gutter)));
  background: color-mix(in srgb, var(--paper) 75%, transparent);
  backdrop-filter: saturate(1.4) blur(16px);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid var(--rule);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  flex-shrink: 0;
}

.brand:hover {
  color: var(--ink);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 9px;
  background: var(--brand-gradient);
  color: var(--on-btn);
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  direction: ltr;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.4;
  letter-spacing: var(--tracking-display);
  white-space: nowrap;
}

/* Progress hides behind a trophy; the panel opens under it like the world menu. */
.progress-menu {
  position: relative;
  flex: none;
}

.topbar-tools .progress-trigger {
  min-height: 46px;
  padding-inline: 12px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
}

.progress-trigger-label {
  display: none;
}

.progress-panel {
  display: grid;
  gap: var(--s-2);
  inset-inline: auto;
  inset-inline-end: 0;
  width: min(300px, 86vw);
}

.progress-panel .world-menu-title {
  margin: 0;
}

.progress-panel-summary {
  color: var(--ink);
}

.progress-panel-detail {
  font-size: var(--fs-sm);
  color: var(--ink-2);
}

.path-progress-bar {
  display: block;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  overflow: hidden;
}

.path-progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand-gradient);
  transition: width var(--dur-fast);
}

.topbar-file {
  white-space: nowrap;
}

.world-menu {
  position: relative;
  flex: 0 0 clamp(130px, 22vw, 300px);
}

.topbar-tools .world-menu-trigger {
  justify-content: flex-start;
  width: 100%;
  min-height: 46px;
  padding-inline: 14px;
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.world-menu-trigger .icon:last-child {
  margin-inline-start: auto;
}

.world-menu-panel {
  position: absolute;
  inset-block-start: calc(100% + 8px);
  inset-inline: 0;
  z-index: 50;
  padding: var(--s-3);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-2);
}

.world-menu-panel[hidden] {
  display: none;
}

.world-menu-title {
  display: block;
  margin-block-end: var(--s-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-2);
}

.world-menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.world-menu-item:hover,
.world-menu-item:focus-visible {
  background: var(--surface-2);
}

.world-menu-item[aria-checked="true"] {
  font-weight: 700;
}

.topbar-tools {
  display: flex;
  flex: 0 1 auto;
  margin-inline-start: auto;
  align-items: center;
  gap: var(--s-2);
}

.xp-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 12px;
  border: 1px solid var(--rule);
  border-radius: var(--r-pill);
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}

.xp-chip-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: var(--fs-sm);
  color: var(--ink);
}

.xp-chip-label {
  font-size: var(--fs-xs);
  color: var(--ink-3);
}

.xp-chip.is-bumped {
  animation: xp-bump 700ms var(--ease);
}

@keyframes xp-bump {
  0% { transform: scale(1); background: var(--surface); }
  30% { transform: scale(1.12); background: var(--highlight); }
  100% { transform: scale(1); background: var(--surface); }
}

/* Language switch: a quiet chip in the other language's own script and font. */
.founder-link {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: var(--s-2);
  height: 38px;
  padding-inline: 6px 12px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.founder-link:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.founder-link img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
}

.lang-switch {
  display: inline-grid;
  place-items: center;
  min-width: 38px;
  height: 38px;
  padding-inline: 10px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color var(--dur-fast), color var(--dur-fast);
}

.lang-switch:hover {
  border-color: color-mix(in srgb, var(--teal) 55%, var(--rule));
  color: var(--teal);
}

.lang-switch-short {
  display: none;
}

.lang-switch[lang="ar"] {
  font-family: "Cairo", "Segoe UI", Tahoma, sans-serif;
}

.lang-switch[lang="en"] {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
}

.menu-toggle {
  display: none;
}

.icon-button:hover {
  border-color: color-mix(in srgb, var(--teal) 55%, var(--rule));
  color: var(--teal);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------ main view */

.view {
  flex: 1;
  width: 100%;
  outline: none;
}

.page {
  width: 100%;
  max-width: var(--page-width);
  margin-inline: auto;
  padding-inline: var(--gutter);
  padding-block: var(--s-6) var(--s-8);
}

.page-narrow {
  max-width: calc(var(--content-width) + 2 * var(--gutter));
}

/* Eyebrow: the site's quiet teal pill that names a section. */
.eyebrow {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 0.45rem;
  width: max-content;
  max-width: 100%;
  padding: 0.3rem 0.85rem;
  border: 1px solid color-mix(in srgb, var(--teal) 32%, transparent);
  border-radius: var(--r-pill);
  background-color: var(--teal-soft);
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.5;
}

:root[lang="en"] .eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ------------------------------------------------------------------ footer */

.site-foot {
  padding-block: var(--s-6) calc(var(--s-4) + env(safe-area-inset-bottom, 0px));
  /* The band spans the screen, but its contents line up with the page column, like the header. */
  padding-inline: max(var(--gutter), calc((100% - var(--page-width)) / 2 + var(--gutter)));
  border-top: 1px solid var(--rule);
  background: var(--surface);
  font-size: var(--fs-sm);
  color: var(--ink-3);
}

.site-foot a {
  color: var(--ink-2);
  text-decoration: none;
}

.site-foot a:hover {
  color: var(--accent);
}

.foot-inner {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr 1fr;
  gap: var(--s-5) var(--s-6);
  align-items: start;
}

.foot-about p {
  max-width: 38ch;
  margin-block: var(--s-3) 0;
  line-height: 1.8;
}

.site-foot .foot-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  color: var(--ink);
  font-weight: 700;
}

.foot-title {
  margin: 0;
  color: var(--ink);
  font-weight: 700;
}

.foot-links {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--s-2);
}

.foot-help {
  display: grid;
  align-content: start;
  justify-items: start;
  gap: var(--s-2);
}

.foot-help p {
  margin: 0;
}

.site-foot .foot-whatsapp {
  margin-top: var(--s-1);
  color: var(--on-btn);
  text-decoration: none;
}

.site-foot .foot-whatsapp:hover {
  color: var(--on-btn);
}

.foot-bottom {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  margin-block-start: var(--s-5);
  padding-block-start: var(--s-4);
  border-top: 1px solid var(--rule);
}

.foot-bottom a {
  font-weight: 600;
}

@media (max-width: 760px) {
  .foot-inner {
    grid-template-columns: 1fr;
  }
}

/* ------------------------------------------------------------------ boot screen */

.boot {
  min-height: calc(100vh - var(--topbar-height) - 40px);
  display: grid;
  place-items: center;
  padding-inline: var(--gutter);
  padding-block: var(--s-7);
}

.boot-card {
  display: grid;
  justify-items: center;
  gap: var(--s-3);
  text-align: center;
}

.boot-grid {
  width: 150px;
  height: 90px;
}

.boot-grid rect:first-child,
.boot-grid path {
  fill: var(--surface);
  stroke: var(--rule-strong);
  stroke-width: 1.4;
}

.boot-grid path {
  fill: none;
}

.boot-scan {
  fill: var(--highlight-band);
  stroke: none;
  animation: boot-scan 1.6s var(--ease) infinite;
}

@keyframes boot-scan {
  0% { transform: translateY(0); }
  33% { transform: translateY(18px); }
  66% { transform: translateY(36px); }
  100% { transform: translateY(0); }
}

.boot-title {
  font-size: var(--fs-xl);
}

.boot-status {
  color: var(--ink-2);
  font-size: var(--fs-sm);
}

.boot-error {
  max-width: 520px;
  padding: var(--s-4);
  border: 1px solid var(--bad);
  border-radius: var(--r-md);
  background: var(--bad-soft);
  color: var(--ink);
  text-align: start;
}

@media (max-width: 1040px) {
  .topbar-file-label,
  .founder-link-label {
    display: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    gap: var(--s-2);
  }

  .brand-name {
    font-size: 1.12rem;
  }

  .menu-toggle {
    display: inline-grid;
    flex: none;
    margin-inline-start: auto;
  }

  /* The header tools fold into a panel under the bar, opened by .menu-toggle. */
  .topbar-tools {
    display: none;
    position: absolute;
    inset-block-start: 100%;
    inset-inline: 0;
    flex-direction: column;
    align-items: stretch;
    max-height: calc(100dvh - var(--topbar-height));
    margin-inline-start: 0;
    padding: var(--s-3) var(--gutter);
    overflow-y: auto;
    border-bottom: 1px solid var(--rule);
    background: var(--surface);
    box-shadow: var(--shadow-2);
  }

  .topbar.is-open .topbar-tools {
    display: flex;
  }

  .topbar-file-label {
    display: inline;
  }

  .topbar-tools .topbar-file {
    justify-content: flex-start;
    width: 100%;
  }

  .world-menu {
    flex: none;
  }

  .xp-chip,
  /* In the phone menu the founder link is a full row, with its label back. */
  .founder-link {
    justify-content: center;
    width: 100%;
    border-radius: var(--r-md);
  }

  .founder-link-label {
    display: inline;
  }

  .lang-switch {
    justify-content: center;
    text-align: center;
  }

  .topbar-tools .icon-button {
    width: 100%;
  }

  /* Progress is a full row in the phone menu, with its label. */
  .topbar-tools .progress-trigger {
    justify-content: flex-start;
    width: 100%;
  }

  .progress-trigger-label {
    display: inline;
  }

  /* The world list opens in place, inside the panel. */
  .world-menu-panel {
    position: static;
    width: auto;
    margin-block-start: var(--s-2);
    border-radius: var(--r-md);
    background: var(--surface-2);
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
