/* 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;
}

/* ------------------------------------------------------------------ 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;
  padding-inline: 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 {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.brand-mark-frame {
  fill: var(--surface);
  stroke: var(--ink);
  stroke-width: 1.6;
}

.brand-mark-rules {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.2;
  opacity: 0.45;
}

/* The highlighted row carries the brand gradient (defined in the page's SVG defs). */
.brand-mark-hl {
  fill: url(#brand-gradient);
}

.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;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-inline-start: var(--s-4);
  overflow-x: auto;
  scrollbar-width: none;
}

.topnav::-webkit-scrollbar {
  display: none;
}

.topnav-link {
  position: relative;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 500;
  font-size: var(--fs-sm);
  white-space: nowrap;
  transition: color var(--dur-fast), background var(--dur-fast);
}

.topnav-link:hover {
  color: var(--ink);
  background: var(--surface-2);
}

/* Current page: the site's gradient underline. */
.topnav-link[aria-current="page"] {
  color: var(--ink);
}

.topnav-link[aria-current="page"]::after {
  content: "";
  position: absolute;
  inset-inline: 12px;
  bottom: -2px;
  height: 2px;
  border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--grad-a), var(--grad-c));
}

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

.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. */
.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: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif;
}

.lang-switch[lang="en"] {
  font-family: "Plus Jakarta Sans", "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);
}

.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 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2) var(--s-4);
  width: 100%;
  max-width: var(--page-width);
  margin-inline: auto;
  padding: var(--s-5) var(--gutter) calc(var(--s-5) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--rule);
  font-size: var(--fs-sm);
  color: var(--ink-3);
}

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

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

/* ------------------------------------------------------------------ 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: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: var(--s-2);
  }

  .topnav {
    order: 3;
    width: 100%;
    margin-inline-start: 0;
    justify-content: space-between;
  }

  .topnav-link {
    padding: 4px 8px;
  }

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

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

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

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