/* =========================================================
   Mobius | موبيوس
   A night-sky library: an interactive star chart on the home
   page, one live figure per subject, books on level shelves.
   ========================================================= */

/* ---------- Fonts ----------
   Served from this site (fonts/), not from Google, so a visit sends nobody
   else the visitor's address. Same font files Google Fonts uses (SIL Open Font
   License, see fonts/OFL.txt), cut down to the letters the site needs.
   A browser only downloads a file when the page uses one of its letters. */
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/newsreader.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Newsreader";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/newsreader-extra.woff2") format("woff2");
  unicode-range: U+0100-0130, U+0132-0151, U+0154-017F, U+0218-021B, U+0300-0303, U+0305-0307, U+2070-2073, U+2075-209F, U+2100-2121, U+2123-214F, U+2190, U+2192, U+2194-2199;
}
@font-face {
  font-family: "Newsreader";
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/newsreader-italic.woff2") format("woff2");
}
@font-face {
  font-family: "Onest";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/onest.woff2") format("woff2");
}
@font-face {
  font-family: "Readex Pro";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("../fonts/readex-pro.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F;
}
@font-face {
  font-family: "Noto Sans Arabic";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("../fonts/noto-sans-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+2010-2011, U+204F, U+25CC, U+2E41;
}
@font-face {
  font-family: "Noto Naskh Arabic";
  font-style: normal;
  font-weight: 500 600;
  font-display: swap;
  src: url("../fonts/noto-naskh-arabic.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+FB50-FDFF, U+FE70-FEFF, U+200C-200F, U+2010-2011, U+204F, U+25CC, U+2E41;
}

:root {
  color-scheme: dark;

  /* night sky */
  --space-0: #070618;      /* deepest sky */
  --space-1: #100d2c;      /* indigo, top of the page */
  --panel: #131034;        /* figure panels */
  --panel-2: #1a1642;      /* panel on hover */
  --line: rgba(196, 186, 255, 0.12);
  --line-2: rgba(196, 186, 255, 0.22);

  /* light */
  --star: #f4efe4;         /* text */
  --dust: #a49fc4;         /* secondary text */
  --faint: #8580a8;        /* captions (4.5:1 or better on panels) */
  --brass: #f0b44a;        /* accent */
  --rose: #ff7a93;
  --ice: #8fd3ff;

  /* five levels, inner orbit to outer */
  --lv-beginner: #6fe3b4;
  --lv-easy: #77c6ff;
  --lv-medium: #f0b44a;
  --lv-hard: #ff7a6b;
  --lv-extreme: #c39bff;

  --serif: "Newsreader", "Iowan Old Style", Georgia, serif;
  --sans: "Onest", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --arabic: "Readex Pro", "Onest", system-ui, sans-serif;

  --max: 1180px;

  /* the page colour itself (the hero keeps its own night colours, so it needs this to meet the page) */
  --page-bg: #070618;

  /* corners: big panels, cards, small controls */
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 8px;

  /* motion: one easing for things arriving, one for small state changes */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 0.16s;
  --t-mid: 0.28s;
  --t-slow: 0.5s;
}

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

html {
  background: var(--space-0);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--space-1) 0, var(--space-0) 560px) var(--space-0);
  color: var(--star);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* paints the phone status-bar band behind the sticky header */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 30;
  background: var(--band, #100d2c);
  transition: background-color var(--t-mid) var(--ease);
}

/* on the home page the sky shows through until the header turns solid */
.page-home:not(.is-scrolled)::before {
  background: transparent;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 3px;
  border-radius: 4px;
}

::selection {
  background: var(--brass);
  color: var(--space-0);
}

[lang="ar"] {
  font-family: var(--arabic);
}

[hidden] {
  display: none !important;
}

.wrap {
  width: min(100% - 32px, var(--max));
  margin-inline: auto;
}

main {
  flex: 1;
}

main:focus {
  outline: none;
}

h1,
h2,
h3 {
  text-wrap: balance;
  font-weight: 500;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 20;
  background: rgba(16, 13, 44, 0.8);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

/* on the home page the header floats over the sky, and gets its background back once you scroll */
.page-home .site-header {
  position: fixed;
  inset: env(safe-area-inset-top, 0px) 0 auto;
  background: transparent;
  border-bottom-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.page-home .site-header.is-solid {
  background: rgba(16, 13, 44, 0.84);
  border-bottom-color: var(--line);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 18px;
  min-height: 62px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}

.brand svg {
  width: 30px;
  height: 30px;
  flex: none;
}

.brand-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
  line-height: 1;
}

.brand-ar {
  color: var(--dust);
  font-size: 0.92rem;
}

.nav {
  display: flex;
  gap: 22px;
  margin-inline-start: auto;
}

.nav a {
  position: relative;
  padding: 8px 0;
  color: var(--dust);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.nav a:hover {
  color: var(--star);
}

.nav a[aria-current="page"] {
  color: var(--star);
}

.nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  height: 2px;
  background: var(--brass);
}

@media (max-width: 440px) {
  .brand-ar {
    display: none;
  }
  .nav {
    gap: 16px;
  }
  .nav a {
    font-size: 0.9rem;
  }
}

/* ---------- Home: hero ---------- */
.hero {
  position: relative;
  min-height: clamp(540px, 84vh, 800px);
  min-height: clamp(540px, 84svh, 800px); /* phones: ignore the browser bar so the hero does not jump */
  display: grid;
  align-items: center;
  overflow: hidden;
  isolation: isolate;
}

.hero-sky {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  touch-action: pan-y;
}

/* keeps the words readable over the sky */
.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(ellipse 55% 50% at 20% 52%, rgba(7, 6, 24, 0.7), transparent 72%);
}

html[dir="rtl"] .hero::after {
  background: radial-gradient(ellipse 55% 50% at 80% 52%, rgba(7, 6, 24, 0.7), transparent 72%);
}

/* where the sky ends: the curved edge of a planet, lit by a thin atmosphere.
   The page below is the planet's surface, so it takes the page colour. */
.horizon {
  --rise: clamp(22px, 4.4vw, 62px);
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: -1;
  width: 320vw;
  height: 150vw;
  border-radius: 50%;
  transform: translate(-50%, calc(100% - var(--rise)));
  will-change: transform; /* painted once, then only composited */
  background: var(--page-bg);
  box-shadow:
    0 -1px 0 rgba(255, 236, 214, 0.42),
    0 -6px 22px rgba(205, 184, 255, 0.26),
    0 -30px 80px rgba(140, 112, 255, 0.2);
  pointer-events: none;
}

/* the sky brightens a little just above the horizon */
.hero::before {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 42%;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, transparent, rgba(120, 92, 220, 0.16) 80%, rgba(255, 196, 160, 0.1));
}

.hero-copy {
  padding-block: 112px 112px;
  pointer-events: none;
}

/* the page opens on one short moment: the name, then the line under it */
@media (prefers-reduced-motion: no-preference) {
  .hero-copy > * {
    animation: hero-in 0.9s var(--ease-out) both;
  }
  .hero-copy > :nth-child(2) { animation-delay: 0.12s; }
  .hero-copy > :nth-child(3) { animation-delay: 0.24s; }
  .hero-sky {
    animation: sky-in 1.4s ease-out both;
  }
}

/* starts at 1% rather than 0: invisible all the same, but the browser then counts the
   title as painted from the first frame (a fade from 0 would make it count as late) */
@keyframes hero-in {
  from {
    opacity: 0.01;
    transform: translateY(14px);
    filter: blur(4px);
  }
}

@keyframes sky-in {
  from { opacity: 0; }
}

.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(3.4rem, 12.5vw, 8rem);
  line-height: 0.95;
  letter-spacing: 0.04em;
  color: var(--star);
}

.hero-ar {
  margin: 10px 0 0;
  font-weight: 500;
  font-size: clamp(1.25rem, 3.8vw, 1.7rem);
  color: var(--brass);
}

.hero-line {
  margin: 22px 0 0;
  max-width: 25rem;
  font-size: clamp(1.08rem, 2.6vw, 1.22rem);
  line-height: 1.5;
  color: var(--star);
}

/* ---------- Home: the two ways in ---------- */
/* the two doors stand on the surface, just below the horizon */
.doors {
  display: grid;
  gap: 16px;
  margin-top: 20px;
  position: relative;
  z-index: 2;
}

@media (min-width: 760px) {
  .doors {
    grid-template-columns: 1fr 1fr;
    gap: 24px;
  }
}

.door {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-2);
  background: var(--panel);
  text-decoration: none;
  transition: border-color var(--t-mid) var(--ease), background-color var(--t-mid) var(--ease), transform var(--t-fast) var(--ease);
}

.door canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
}

.door-text {
  padding: 16px 22px 20px;
  border-top: 1px solid var(--line);
}

.door h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.5rem, 3.6vw, 1.9rem);
  line-height: 1.15;
  transition: color 0.2s ease;
}

.door p {
  margin: 4px 0 0;
  color: var(--dust);
}

.door:hover,
.door:focus-visible {
  border-color: color-mix(in srgb, var(--brass) 55%, transparent);
  background: var(--panel-2);
}

.door:hover h2,
.door:focus-visible h2 {
  color: var(--brass);
}

/* ---------- Home: the five orbits ---------- */
.orbits {
  display: grid;
  gap: 24px;
  align-items: center;
  padding-block: 96px 104px;
}

@media (min-width: 860px) {
  .orbits {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 64px;
  }
}

.orbit-art {
  position: relative;
  width: min(100%, 500px);
  aspect-ratio: 1;
  justify-self: center;
  /* the turning layers are squares; at an angle their corners poke out, so keep them inside */
  overflow: hidden;
}

.orbit-art svg {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* each ring carries a faint trace of its level's colour */
.orbit-ring {
  fill: none;
  stroke: var(--line-2);
  stroke-width: 1;
  transition: stroke var(--t-mid) var(--ease), stroke-width var(--t-mid) var(--ease), opacity var(--t-mid) var(--ease);
}

/* the planets (positions are in the drawing's 600-unit space, set on each .orbit) */
.orbit {
  position: absolute;
  inset: 0;
  transform: rotate(var(--a));
  pointer-events: none;
}

.orbit-turn {
  position: absolute;
  inset: 0;
  animation: spin var(--d) linear infinite;
  will-change: transform;
}

.orbiter {
  position: absolute;
  top: 50%;
  left: calc(50% + var(--r) / 6 * 1%);
  width: calc(var(--s) / 6 * 1%);
  aspect-ratio: 1;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 35%, #fff 0 10%, var(--cv) 46%, var(--cv) 100%);
  transition: transform var(--t-mid) var(--ease-out);
}

/* richer shading where the browser can mix colours (older ones keep the plain look above) */
@supports (color: color-mix(in srgb, red, blue)) {
  .orbit-ring {
    stroke: color-mix(in srgb, var(--lv) 34%, var(--line-2));
  }
  .orbiter {
    background: radial-gradient(circle at 35% 35%, #fff 0 10%, var(--cv) 46%, color-mix(in srgb, var(--cv) 62%, #05040f) 100%);
    box-shadow: 0 0 14px 1px color-mix(in srgb, var(--cv) 45%, transparent);
  }
}

/* pointing at a level in the list lights up its orbit */
@media (hover: hover) {
  .orbits:has(.level-list li:hover) .orbit-ring {
    opacity: 0.45;
  }
  .orbits:has(.level-list .lv-beginner:hover) .orbit-ring.lv-beginner,
  .orbits:has(.level-list .lv-easy:hover) .orbit-ring.lv-easy,
  .orbits:has(.level-list .lv-medium:hover) .orbit-ring.lv-medium,
  .orbits:has(.level-list .lv-hard:hover) .orbit-ring.lv-hard,
  .orbits:has(.level-list .lv-extreme:hover) .orbit-ring.lv-extreme {
    opacity: 1;
    stroke: var(--lv);
    stroke-width: 2;
  }
  .orbits:has(.level-list .lv-beginner:hover) .orbit.lv-beginner .orbiter,
  .orbits:has(.level-list .lv-easy:hover) .orbit.lv-easy .orbiter,
  .orbits:has(.level-list .lv-medium:hover) .orbit.lv-medium .orbiter,
  .orbits:has(.level-list .lv-hard:hover) .orbit.lv-hard .orbiter,
  .orbits:has(.level-list .lv-extreme:hover) .orbit.lv-extreme .orbiter {
    transform: translate(-50%, -50%) scale(1.45);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.section-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2rem, 5vw, 2.8rem);
  line-height: 1.1;
}

.section-sub {
  margin: 10px 0 0;
  color: var(--dust);
  font-size: 1.05rem;
  max-width: 30rem;
}

.level-list {
  margin: 28px 0 0;
  padding: 0;
  list-style: none;
}

.level-list li {
  display: grid;
  grid-template-columns: 16px auto 1fr;
  align-items: center;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
}

.level-list li:first-child {
  border-top: 1px solid var(--line);
}

.planet {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 8%, var(--lv) 42%, color-mix(in srgb, var(--lv) 55%, #000) 100%);
}

.level-list strong {
  font-weight: 600;
  color: var(--lv);
}

.level-list span:last-child {
  color: var(--dust);
  text-align: right;
}

.lv-beginner { --lv: var(--lv-beginner); }
.lv-easy     { --lv: var(--lv-easy); }
.lv-medium   { --lv: var(--lv-medium); }
.lv-hard     { --lv: var(--lv-hard); }
.lv-extreme  { --lv: var(--lv-extreme); }

/* ---------- Subject index pages ---------- */
.page-top {
  padding-block: 40px 4px;
}

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 0.875rem;
  color: var(--faint);
}

.crumbs a {
  color: var(--dust);
  text-decoration: none;
}

.crumbs a:hover {
  color: var(--brass);
}

.crumbs [aria-current] {
  color: var(--star);
}

.page-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2.4rem, 7vw, 4.2rem);
  line-height: 1.02;
}

.page-sub {
  margin: 12px 0 0;
  color: var(--dust);
  font-size: 1.08rem;
}

.jump {
  display: flex;
  flex-wrap: wrap;
  gap: 22px;
  margin-top: 20px;
}

.jump a {
  color: var(--star);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--line-2);
  text-underline-offset: 5px;
}

.jump a:hover {
  color: var(--brass);
  text-decoration-color: var(--brass);
}

.field {
  padding-block: 40px 8px;
  scroll-margin-top: 80px;
}

.field-title {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 0 0 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.6rem, 4.4vw, 2.1rem);
}

.field-title small {
  margin-left: auto;
  font-family: var(--sans);
  font-size: 0.875rem;
  color: var(--dust);
}

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 18px;
  margin: 0;
  padding: 0;
  list-style: none;
}

@media (min-width: 900px) {
  .tiles--three {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 560px) {
  .tiles {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

.tile {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--panel);
  text-decoration: none;
  transition: border-color var(--t-mid) var(--ease), background-color var(--t-mid) var(--ease), transform var(--t-fast) var(--ease);
}

/* a tap answers with a small press (phones and tablets have no hover) */
@media (hover: none) {
  .tile:active,
  .door:active {
    transform: scale(0.985);
  }
  .book:active .cover {
    transform: scale(0.97);
  }
}

.tile canvas {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
}

.tile-text {
  display: block;
  padding: 12px 16px 15px;
  border-top: 1px solid var(--line);
}

.tile-name {
  display: block;
  font-weight: 600;
  font-size: 1rem;
  line-height: 1.3;
  transition: color 0.2s ease;
}

.tile-cap {
  display: block;
  margin-top: 3px;
  color: var(--faint);
  font-size: 0.84rem;
  line-height: 1.35;
}

@media (max-width: 560px) {
  .tile {
    border-radius: var(--r-sm);
  }
  .tile-text {
    padding: 9px 11px 11px;
  }
  .tile-name {
    font-size: 0.9rem;
  }
  .tile-cap {
    display: none;
  }
}

.tile:hover,
.tile:focus-visible {
  border-color: color-mix(in srgb, var(--brass) 50%, transparent);
  background: var(--panel-2);
}

.tile:hover .tile-name,
.tile:focus-visible .tile-name {
  color: var(--brass);
}

/* ---------- Subject page ---------- */
.banner {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-2);
  background: var(--panel);
  margin-top: 20px;
}

.banner canvas {
  display: block;
  width: 100%;
  height: clamp(240px, 40vw, 380px);
  touch-action: pan-y;
}

.banner-text {
  position: absolute;
  inset: auto 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px 24px;
  padding: 64px 28px 22px;
  background: linear-gradient(180deg, transparent, rgba(7, 6, 24, 0.86));
  pointer-events: none;
}

.banner .crumbs {
  margin-bottom: 6px;
  pointer-events: auto;
}

.banner h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(2rem, 6vw, 3.6rem);
  line-height: 1.04;
}

/* the equation behind the picture, set like a figure caption */
.figure-cap {
  margin: 0 0 6px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.05rem;
  color: var(--dust);
}

.figure-cap sub {
  font-size: 0.7em;
}

/* the figure answers a tap; the small button says what a tap does (scenes.js adds both).
   The figure is always night-coloured, so the button keeps night colours in light mode too. */
.banner.is-playable canvas {
  cursor: pointer;
}

.banner-hint {
  position: absolute;
  top: 12px;
  inset-inline-end: 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px 6px 10px;
  border: 1px solid rgba(196, 186, 255, 0.22);
  border-radius: 999px;
  background: rgba(7, 6, 24, 0.62);
  color: #f4efe4;
  font: 500 0.8rem/1.25 var(--sans);
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}

.banner-hint svg {
  width: 15px;
  height: 15px;
  flex: none;
  color: #f0b44a;
}

.banner-hint:hover {
  border-color: rgba(240, 180, 74, 0.6);
  background: rgba(7, 6, 24, 0.82);
}

.banner-hint:active {
  transform: scale(0.97);
}

html[dir="rtl"] .banner-hint {
  padding: 6px 10px 6px 12px;
}

@media (max-width: 560px) {
  .banner {
    margin-top: 14px;
    border-radius: var(--r-md);
  }
  .banner canvas {
    height: 200px;
  }
  /* on phones the title sits under the picture, so the whole figure stays visible */
  .banner-text {
    position: static;
    display: block;
    padding: 6px 16px 16px;
    background: none;
  }
  .figure-cap {
    margin: 6px 0 0;
    font-size: 0.95rem;
  }
  .banner-hint {
    top: 8px;
    inset-inline-end: 8px;
    padding: 5px 10px 5px 8px;
    font-size: 0.75rem;
  }
}

.pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 26px 0 6px;
}

.pill {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px 7px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--star);
  font: inherit;
  font-weight: 500;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.pill .n {
  color: var(--dust);
  font-variant-numeric: tabular-nums;
}

.pill:hover {
  border-color: var(--lv, var(--brass));
}

.pill[aria-pressed="true"] {
  background: color-mix(in srgb, var(--lv, var(--brass)) 16%, transparent);
  border-color: var(--lv, var(--brass));
}

.pill-all .planet {
  --lv: var(--brass);
}

/* shelves sit side by side, so the levels read left to right like a path */
.shelves {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 44px 40px;
  padding-top: 30px;
}

.shelf {
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.shelf:not(:has(.book)) {
  display: none;
}

.shelf-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--lv);
}

.shelf-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.45rem;
  line-height: 1.1;
  color: var(--star);
}

.books {
  --book-w: 160px;
  display: flex;
  flex-wrap: wrap;
  gap: 28px 22px;
}

@media (max-width: 560px) {
  .shelves {
    gap: 34px 16px;
  }
  .books {
    --book-w: calc((100vw - 48px) / 2);
    gap: 22px 16px;
  }
}

.book {
  display: flex;
  flex-direction: column;
  width: var(--book-w);
  max-width: 100%;
  min-width: 0;
  text-decoration: none;
  perspective: 800px;
}

.cover {
  --rx: 0deg;
  --ry: 0deg;
  --gx: 50%;
  --gy: 30%;
  position: relative;
  display: block;
  aspect-ratio: 2 / 3;
  max-width: 100%;
  overflow: hidden;
  border-radius: 3px;
  background: var(--panel-2);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 14px 26px -16px rgba(0, 0, 0, 0.9);
  transform: rotateX(var(--rx)) rotateY(var(--ry));
  transition: transform 0.18s ease-out, box-shadow 0.2s ease;
}

.cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* a faint sheen that follows the pointer */
.cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--gx) var(--gy), rgba(255, 255, 255, 0.18), transparent 55%);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.book:hover .cover,
.book:focus-visible .cover {
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.14),
    0 22px 34px -18px rgba(0, 0, 0, 0.95);
}

.book:hover .cover::after {
  opacity: 1;
}

/* ---------- drawn covers ----------
   Every book gets a cover drawn in its level's colours (script.js makes it):
   title, author, and the level's orbits, one ring for Beginner up to five for
   Extreme, as on the home page. A real cover image sits on top of it and
   fades in once loaded; with no image, the drawn cover is what you see.
   Covers are objects, so they keep the same colours in light and dark mode. */
/* --cv: the level's light; --cv-a / --cv-b: the cover cloth, top and bottom */
.lv-beginner { --cv: #6fe3b4; --cv-a: #134540; --cv-b: #07191c; }
.lv-easy     { --cv: #77c6ff; --cv-a: #1b3a72; --cv-b: #0a1332; }
.lv-medium   { --cv: #f0b44a; --cv-a: #5a3a10; --cv-b: #1f1308; }
.lv-hard     { --cv: #ff7a6b; --cv-a: #5e1d2a; --cv-b: #200a12; }
.lv-extreme  { --cv: #c39bff; --cv-a: #3c2470; --cv-b: #150b2c; }

.cover,
.bp-cover {
  container-type: inline-size;
}

.cover img {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.cover::after {
  z-index: 2;
}

html.cover-fx .cover img {
  opacity: 0;
  transition: opacity var(--t-slow) var(--ease);
}

html.cover-fx .cover.is-loaded img {
  opacity: 1;
}

.cover.is-blank img {
  display: none;
}

.cover-blank {
  --cv0: var(--cv, #f0b44a);
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 20px 16px 0 20px;
  padding: 13cqw 11cqw 0 13cqw;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 30% 0%, rgba(255, 255, 255, 0.09), transparent 62%),
    linear-gradient(var(--cb-angle, 168deg), var(--cv-a, #2a2358), var(--cv-b, #0b0a22) 92%);
  color: #f4efe4;
  text-align: left;
  font-family: var(--serif);
}

/* the spine and a pressed frame, so it reads as a bound book */
.cover-blank::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 9px;
  width: 5.5cqw;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.34), rgba(255, 255, 255, 0.07) 72%, rgba(0, 0, 0, 0.12));
}

.cover-blank::after {
  content: "";
  position: absolute;
  inset: 8px 8px 8px 13px;
  inset: 5cqw 5cqw 5cqw 8.5cqw;
  border: 1px solid rgba(244, 239, 228, 0.1);
  border-radius: 2px;
  pointer-events: none;
}

.cb-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.cb-ring {
  fill: none;
  stroke: var(--cv0);
  stroke-opacity: 0.3;
  stroke-width: 0.55;
}

.cb-ring.is-on {
  stroke-opacity: 0.75;
  stroke-width: 0.8;
}

.cb-ring.is-out {
  stroke-opacity: 0.1;
}

.cb-sun {
  fill: #f0b44a;
  opacity: 0.85;
}

.cb-planet {
  fill: var(--cv0);
}

.cb-shine {
  fill: #fff;
  opacity: 0.7;
}

.cb-title,
.cb-sub,
.cb-kind,
.cb-author {
  position: relative;
  display: block;
  max-width: 100%;
  text-wrap: balance;
  overflow-wrap: anywhere;
}

.cb-title {
  font-weight: 500;
  font-size: 1rem;
  font-size: 11cqw;
  line-height: 1.08;
  letter-spacing: -0.005em;
}

.cover-blank[data-len="m"] .cb-title { font-size: 9.6cqw; }
.cover-blank[data-len="l"] .cb-title { font-size: 8.4cqw; }

.cb-sub,
.cb-kind {
  margin-top: 5px;
  margin-top: 3cqw;
  font-style: italic;
  font-size: 0.8rem;
  font-size: 7.4cqw;
  line-height: 1.15;
  color: rgba(244, 239, 228, 0.78);
}

.cb-rule {
  position: relative;
  width: 22px;
  width: 14cqw;
  height: 1px;
  margin: 11px 0 8px;
  margin: 7cqw 0 5cqw;
  background: var(--cv0);
  opacity: 0.9;
}

.cb-author {
  font-family: var(--sans);
  font-weight: 500;
  font-size: 0.7rem;
  font-size: 6.4cqw;
  line-height: 1.3;
  letter-spacing: 0.02em;
  color: rgba(244, 239, 228, 0.7);
}

.book-title {
  margin-top: 12px;
  font-weight: 600;
  font-size: 0.93rem;
  line-height: 1.3;
}

.book:hover .book-title {
  text-decoration: underline;
  text-decoration-color: var(--lv, var(--brass));
  text-underline-offset: 3px;
}

.book-author {
  margin-top: 2px;
  color: var(--dust);
  font-size: 0.84rem;
  line-height: 1.35;
}

.book-note {
  margin-top: 6px;
  align-self: flex-start;
  padding: 1px 8px;
  border-radius: 4px;
  border: 1px solid var(--line-2);
  color: var(--dust);
  font-size: 0.75rem;
}

.page-end {
  height: 96px;
}

/* the page-not-found words sit just under its figure */
.lost-text {
  padding-top: 18px;
}

/* ---------- Privacy and terms pages ----------
   Each page holds an English and an Arabic text; the one for the chosen
   language is shown (Kurdish shows the Arabic one until a Kurdish text exists). */
.legal {
  padding-top: 18px;
}

.legal-text {
  max-width: 46rem;
}

.legal-text[data-for="ar"],
.legal-note {
  display: none;
}

html[data-lang="ar"] .legal-text[data-for="en"],
html[data-lang="ku"] .legal-text[data-for="en"] {
  display: none;
}

html[data-lang="ar"] .legal-text[data-for="ar"],
html[data-lang="ku"] .legal-text[data-for="ar"],
html[data-lang="ku"] .legal-note {
  display: block;
}

.legal-note {
  margin: 0 0 22px;
  padding: 10px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  color: var(--dust);
}

.legal-lead {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.65;
  color: var(--star);
}

.legal h2 {
  margin: 36px 0 8px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.45rem;
  line-height: 1.25;
}

.legal p,
.legal li {
  margin: 0;
  line-height: 1.75;
  color: color-mix(in srgb, var(--star) 88%, var(--dust));
}

.legal ul {
  display: grid;
  gap: 8px;
  margin: 0 0 10px;
  padding-inline-start: 1.25em;
}

.legal ul + p {
  margin-top: 4px;
}

.legal a {
  color: var(--brass);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--brass) 45%, transparent);
  text-underline-offset: 3px;
}

.legal a:hover {
  text-decoration-color: var(--brass);
}

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--line);
  padding-block: 44px 28px;
  color: var(--dust);
  font-size: 0.92rem;
}

.footer-grid {
  display: grid;
  gap: 28px 40px;
}

@media (min-width: 720px) {
  .footer-grid {
    grid-template-columns: 1.6fr 1fr 1fr;
  }
}

.footer-grid h2 {
  margin: 0 0 10px;
  font-family: var(--sans);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--faint);
}

.footer-about {
  margin: 0;
  max-width: 24rem;
}

.footer-about strong {
  display: block;
  margin-bottom: 6px;
  font-family: var(--serif);
  font-weight: 500;
  font-size: 1.35rem;
  color: var(--star);
}

.footer-links {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

.footer-links a {
  color: var(--star);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--brass);
}

.credits {
  margin: 0;
  display: grid;
  gap: 10px;
}

.credits div {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  align-items: baseline;
  gap: 12px;
}

.credits dt {
  color: var(--faint);
  font-size: 0.875rem;
}

.credits dd {
  margin: 0;
  color: var(--star);
  font-weight: 500;
}

.footer-base {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px 24px;
  margin-top: 36px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.84rem;
}

.footer-base p {
  margin: 0;
}

.footer-legal {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 20px;
}

.footer-legal a {
  color: var(--dust);
  text-decoration: none;
}

.footer-legal a:hover {
  color: var(--brass);
}

/* a hidden link that keyboard users meet first: it jumps past the header */
.skip-link {
  position: fixed;
  top: 10px;
  inset-inline-start: 10px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--r-sm);
  background: var(--brass);
  color: var(--space-0);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--t-fast) var(--ease);
}

.skip-link:focus {
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* =========================================================
   Light theme, header tools, search, right-to-left pages,
   the book panel, and moving between pages
   ========================================================= */

/* while a saved Arabic/Kurdish page is being translated */
html.i18n-wait body > header,
html.i18n-wait body > main,
html.i18n-wait body > footer {
  visibility: hidden;
}

/* ---------- Light theme ----------
   Set on <body>, so the moving figures (which read their colours
   from <html>) keep their night-sky palette inside dark panels. */
html[data-theme="light"] body {
  color-scheme: light;
  --space-0: #f7f5ef;
  --space-1: #e8e4f6;
  --panel: #ffffff;
  --panel-2: #f2effa;
  --line: rgba(38, 30, 104, 0.12);
  --line-2: rgba(38, 30, 104, 0.22);
  --star: #17133a;
  --dust: #4c4770;
  --faint: #66618a;
  --brass: #9a5b06;
  --rose: #c23a57;
  --ice: #1f6fae;
  --lv-beginner: #0e7a53;
  --lv-easy: #1f6fbf;
  --lv-medium: #985a07;
  --lv-hard: #c4402f;
  --lv-extreme: #7448c9;
  --header-bg: rgba(247, 245, 239, 0.86);
  --band: #f5f3ef;
  --page-bg: #f7f5ef;
}

html[data-theme="light"] {
  background: #f7f5ef;
}

/* the night-sky pieces stay dark in light mode */
html[data-theme="light"] .hero,
html[data-theme="light"] .page-home .site-header:not(.is-solid) {
  --space-0: #070618;
  --space-1: #100d2c;
  --panel: #131034;
  --panel-2: #1a1642;
  --line: rgba(196, 186, 255, 0.12);
  --line-2: rgba(196, 186, 255, 0.22);
  --star: #f4efe4;
  --dust: #a49fc4;
  --faint: #8580a8;
  --brass: #f0b44a;
  color: var(--star);
}

html[data-theme="light"] .hero {
  background: linear-gradient(180deg, #100d2c, #0b0a22);
}

/* by day the atmosphere at the horizon glows a little brighter */
html[data-theme="light"] .horizon {
  box-shadow:
    0 -1px 0 rgba(255, 240, 222, 0.75),
    0 -5px 18px rgba(222, 205, 255, 0.5),
    0 -26px 70px rgba(160, 132, 255, 0.34);
}

html[data-theme="light"] .tile canvas,
html[data-theme="light"] .door canvas,
html[data-theme="light"] .banner canvas {
  background: radial-gradient(ellipse at 50% 40%, #1a1642, #100d2c 75%);
}

html[data-theme="light"] .site-header,
html[data-theme="light"] .page-home .site-header.is-solid {
  background: var(--header-bg);
}

html[data-theme="light"] .page-home .site-header:not(.is-solid) {
  background: transparent;
}

html[data-theme="light"] .brand svg ellipse {
  stroke: var(--star);
}

html[data-theme="light"] .tile,
html[data-theme="light"] .door {
  box-shadow: 0 1px 2px rgba(38, 30, 104, 0.06), 0 10px 24px -18px rgba(38, 30, 104, 0.35);
}

html[data-theme="light"] .cover {
  box-shadow: 0 0 0 1px rgba(38, 30, 104, 0.1), 0 14px 26px -16px rgba(38, 30, 104, 0.55);
}

html[data-theme="light"] ::selection {
  color: #fff;
}

@media (min-width: 561px) {
  html[data-theme="light"] .banner-text {
    --star: #f4efe4;
    --dust: #a49fc4;
    --faint: #8580a8;
    --brass: #f0b44a;
    color: var(--star);
  }
}

/* ---------- Header tools ---------- */
.tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  min-width: 38px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--line-2);
  background: color-mix(in srgb, var(--panel) 55%, transparent);
  color: var(--star);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.tool:hover {
  border-color: color-mix(in srgb, var(--brass) 60%, transparent);
  color: var(--brass);
}

.tool svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.tool-search {
  min-width: 170px;
  justify-content: flex-start;
  color: var(--dust);
}

.tool-label {
  flex: 1;
  text-align: start;
}

.tool-kbd {
  padding: 1px 7px;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  font: 500 0.75rem/1.4 var(--sans);
  color: var(--faint);
}

.tool-theme .i-moon,
html[data-theme="light"] .tool-theme .i-sun {
  display: none;
}

html[data-theme="light"] .tool-theme .i-moon {
  display: block;
}

.tool-code {
  min-width: 1.2em;
  font-size: 0.85rem;
}

.lang {
  position: relative;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 50;
  min-width: 200px;
  margin: 0;
  padding: 6px;
  list-style: none;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.6);
}

.lang-menu button {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--star);
  font: inherit;
  font-size: 0.95rem;
  text-align: start;
  cursor: pointer;
}

.lang-menu button:hover,
.lang-menu button:focus-visible {
  background: var(--panel-2);
  outline: none;
}

.lang-short {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--line-2);
  color: var(--dust);
  font-size: 0.78rem;
  font-weight: 600;
}

.lang-menu [aria-checked="true"] .lang-short {
  border-color: var(--brass);
  background: var(--brass);
  color: var(--space-0);
}

.lang-menu [aria-checked="true"] .lang-name {
  font-weight: 600;
}

.lang-menu [lang="ar"],
.lang-menu [lang="ku"] {
  font-family: "Noto Sans Arabic", var(--sans);
}

@media (max-width: 860px) {
  .tool-search {
    min-width: 38px;
    padding: 0;
    justify-content: center;
  }
  .tool-label,
  .tool-kbd {
    display: none;
  }
}

/* phones: brand and tools on one row, the two sections on a second row.
   The header is solid there: a live blur would be recomputed on every frame
   of the moving figures scrolling under it, which costs smoothness. */
@media (max-width: 640px) {
  .site-header,
  .page-home .site-header.is-solid {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgba(16, 13, 44, 0.97);
  }
  html[data-theme="light"] .site-header,
  html[data-theme="light"] .page-home .site-header.is-solid {
    background: rgba(247, 245, 239, 0.97);
  }
  .header-inner {
    flex-wrap: wrap;
    min-height: 0;
    padding-top: 10px;
  }
  .brand {
    min-height: 38px; /* the height of the buttons added beside it, so nothing moves when they arrive */
  }
  .tools {
    margin-inline-start: auto;
  }
  .nav {
    order: 3;
    width: 100%;
    margin: 0;
    gap: 22px;
    border-top: 1px solid var(--line);
  }
  .nav a {
    padding: 9px 0 10px;
  }
  .nav a[aria-current="page"]::after {
    bottom: 0;
  }
  .page-home .site-header:not(.is-solid) .nav {
    border-top-color: transparent;
  }
}

/* ---------- Search dialog ---------- */
html.search-open {
  overflow: hidden;
}

.search {
  width: min(640px, calc(100% - 32px));
  max-height: min(640px, calc(100% - 96px));
  margin: 72px auto auto;
  padding: 0;
  border-radius: 16px;
  border: 1px solid var(--line-2);
  background: var(--panel);
  color: var(--star);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}

.search[open] {
  display: flex;
  flex-direction: column;
}

.search::backdrop {
  background: rgba(7, 6, 24, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* dialogs answer the tap: they arrive from where they will sit, and leave the same way
   (the rules that use these are at the end of the book panel section) */
@keyframes dlg-drop {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
}

@keyframes dlg-rise {
  from { opacity: 0; transform: translateY(18px) scale(0.985); }
}

@keyframes dlg-sheet {
  from { transform: translateY(100%); }
}

@keyframes dlg-fade {
  from { opacity: 0; }
}

@keyframes dlg-out {
  to { opacity: 0; transform: translateY(8px) scale(0.985); }
}

@keyframes dlg-sheet-out {
  to { transform: translateY(100%); }
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  padding-inline: 16px 8px;
  border-bottom: 1px solid var(--line);
}

.search-box > svg {
  width: 20px;
  height: 20px;
  flex: none;
  color: var(--brass);
}

.search-box input {
  flex: 1;
  min-width: 0;
  height: 48px;
  border: 0;
  background: transparent;
  color: var(--star);
  font: inherit;
  font-size: 1.08rem;
  outline: none;
}

.search-box input::placeholder {
  color: var(--faint);
}

.search-box input::-webkit-search-cancel-button {
  display: none;
}

.search-close {
  appearance: none;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--dust);
  cursor: pointer;
}

.search-close:hover {
  background: var(--panel-2);
  color: var(--star);
}

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

.search-results {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 8px 12px;
}

.search-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 10px 6px;
  font: 500 0.8rem/1.2 var(--sans);
  color: var(--faint);
}

.search-count {
  padding: 0 7px;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  font-variant-numeric: tabular-nums;
}

.result {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 10px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--star);
}

.result:hover,
.result[aria-selected="true"] {
  background: var(--panel-2);
}

.result[aria-selected="true"] {
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brass) 45%, transparent);
}

.result-orb {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 8%, var(--brass) 45%, color-mix(in srgb, var(--brass) 45%, #000) 100%);
  opacity: 0.85;
}

/* a tiny drawn cover (see .cover-blank in style.css), shown until or instead of the image */
.result-cover,
.chat-book-cover {
  --cv0: var(--cv, #f0b44a);
  background:
    radial-gradient(circle at 100% 100%, rgba(240, 180, 74, 0.9) 0 3px, transparent 3.6px),
    radial-gradient(circle at 100% 100%, transparent 0 10px, var(--cv0) 10.5px 11.3px, transparent 11.8px),
    radial-gradient(120% 70% at 30% 0%, rgba(255, 255, 255, 0.09), transparent 62%),
    linear-gradient(168deg, var(--cv-a, #2a2358), var(--cv-b, #0b0a22) 92%);
  box-shadow: inset 2px 0 0 rgba(0, 0, 0, 0.28);
}

.result-cover {
  flex: none;
  width: 36px;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 3px;
}

.result-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-text {
  display: grid;
  flex: 1;
  min-width: 0;
}

.result-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
  unicode-bidi: plaintext;
  text-align: start;
}

.result-author {
  color: var(--dust);
  font-size: 0.85rem;
  unicode-bidi: plaintext;
  text-align: start;
}

.result-meta {
  margin-top: 2px;
  color: var(--faint);
  font-size: 0.8rem;
}

.result-level {
  color: var(--lv, var(--brass));
  font-weight: 600;
}

.result-title,
.result-author,
.result-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-hint,
.search-empty {
  margin: 14px 10px 6px;
  color: var(--dust);
}

.search-empty strong {
  color: var(--star);
}

.search-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 10px 4px;
}

.search-chip {
  padding: 6px 12px;
  border-radius: 99px;
  border: 1px solid var(--line-2);
  color: var(--star);
  font-size: 0.88rem;
  text-decoration: none;
}

.search-chip:hover {
  border-color: var(--brass);
  color: var(--brass);
}

@media (max-width: 560px) {
  .search {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
  }
}

/* a book found through search glows for a moment */
.book.is-found .cover {
  animation: found 2.4s ease-out;
}

@keyframes found {
  0%, 40% {
    box-shadow: 0 0 0 3px var(--lv, var(--brass)), 0 0 34px 4px color-mix(in srgb, var(--lv, var(--brass)) 55%, transparent);
  }
  100% {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 14px 26px -16px rgba(0, 0, 0, 0.9);
  }
}

/* ---------- Arabic & Kurdish (right to left) ---------- */
html[dir="rtl"] {
  --serif: "Newsreader", "Noto Naskh Arabic", Georgia, serif;
  --sans: "Onest", "Noto Sans Arabic", system-ui, sans-serif;
  --arabic: "Noto Sans Arabic", "Readex Pro", system-ui, sans-serif;
}

html[dir="rtl"] body {
  line-height: 1.75;
}

html[dir="rtl"] .page-title,
html[dir="rtl"] .section-title,
html[dir="rtl"] .banner h1,
html[dir="rtl"] .door h2,
html[dir="rtl"] .field-title {
  line-height: 1.35;
}

html[dir="rtl"] .field-title small {
  margin-left: 0;
  margin-inline-start: auto;
}

html[dir="rtl"] .level-list span:last-child {
  text-align: left;
}

html[dir="rtl"] .pill {
  padding: 7px 11px 7px 13px;
}

/* book titles, authors and equations stay left-to-right */
html[dir="rtl"] .book-title,
html[dir="rtl"] .book-author,
html[dir="rtl"] .cover-blank {
  unicode-bidi: plaintext;
  text-align: start;
}

html[dir="rtl"] .figure-cap {
  unicode-bidi: isolate;
}

html[dir="rtl"] .wordmark,
html[dir="rtl"] .brand-name {
  direction: ltr;
}

html[dir="rtl"] .wordmark {
  text-align: right;
}

html[dir="rtl"] .result-title,
html[dir="rtl"] .result-author {
  text-align: right;
}

html[dir="rtl"] .credits div {
  grid-template-columns: 7.5rem 1fr;
}

@media (max-width: 440px) {
  html[dir="rtl"] .nav {
    gap: 18px;
  }
}

/* ---------- note shown when a book's link isn't added yet ---------- */
.soon-toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 80;
  width: max-content;
  max-width: calc(100vw - 32px);
  margin: 0 auto;
  text-align: center;
  padding: 11px 18px 11px 16px;
  border: 1px solid var(--line-2);
  border-radius: 999px;
  background: var(--panel);
  color: var(--star);
  font-size: 0.92rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.soon-toast::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-inline-end: 9px;
  border-radius: 50%;
  background: var(--brass);
  vertical-align: 1px;
}
.soon-toast.is-on {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .soon-toast { transition: none; }
}

/* ---------- Book panel (book-panel.js) ---------- */
html.book-open {
  overflow: hidden;
}
.book-panel {
  --lv: var(--brass);
  width: min(720px, calc(100% - 32px));
  max-height: min(860px, calc(100% - 64px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 18px;
  background: var(--panel);
  color: var(--star);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, 0.8);
  overflow: hidden;
}
.book-panel.lv-beginner { --lv: var(--lv-beginner); }
.book-panel.lv-easy { --lv: var(--lv-easy); }
.book-panel.lv-medium { --lv: var(--lv-medium); }
.book-panel.lv-hard { --lv: var(--lv-hard); }
.book-panel.lv-extreme { --lv: var(--lv-extreme); }
.book-panel[open] {
  display: flex;
  flex-direction: column;
}
.book-panel::backdrop {
  background: rgba(7, 6, 24, 0.66);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}
.bp-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 32px 32px 36px;
  border-top: 3px solid var(--lv);
}
.bp-close {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-2);
  border-radius: 50%;
  background: var(--panel);
  color: var(--star);
  cursor: pointer;
}
.bp-close:hover { border-color: var(--lv); }
.bp-close svg { width: 18px; height: 18px; }

.bp-head {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 26px;
  align-items: end;
  padding-inline-end: 34px;
}
.bp-cover {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 4px;
  background: var(--panel-2);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 22px 34px -18px rgba(0, 0, 0, 0.95);
}
.bp-cover img { width: 100%; height: 100%; object-fit: cover; }

.bp-level {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 0.85rem;
  color: var(--dust);
}
.bp-level .planet {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--lv);
  box-shadow: 0 0 10px var(--lv);
}
.bp-level-name { color: var(--lv); font-weight: 600; }
.bp-subject { flex-basis: 100%; color: var(--faint); }
.bp-title {
  margin: 0;
  font-family: var(--serif);
  font-weight: 500;
  font-size: clamp(1.6rem, 3.4vw, 2.2rem);
  line-height: 1.12;
}
.bp-author { margin: 8px 0 0; color: var(--dust); font-size: 1rem; }
.bp-note {
  display: inline-block;
  margin: 10px 0 0;
  padding: 1px 8px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  color: var(--dust);
  font-size: 0.78rem;
}
.bp-note[hidden] { display: none; }

.bp-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 26px 0 6px;
}
.bp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  color: var(--star);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.bp-btn svg { width: 19px; height: 19px; flex: none; }
.bp-btn:hover { border-color: var(--lv); }
.bp-read {
  background: var(--brass);
  border-color: var(--brass);
  color: #17133a;
}
.bp-read:hover { background: #f6c66c; border-color: #f6c66c; }
html[data-theme="light"] .bp-read { color: #fff; }
html[data-theme="light"] .bp-read:hover { background: #b06c0d; border-color: #b06c0d; }
.bp-btn[hidden] { display: none; }

.bp-body section {
  padding: 20px 0 0;
  margin-top: 20px;
  border-top: 1px solid var(--line);
}
.bp-body h3 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lv);
}
html[dir="rtl"] .bp-body h3 { letter-spacing: 0; text-transform: none; font-size: 0.95rem; }
.bp-body p {
  margin: 0;
  font-size: 1.02rem;
  line-height: 1.7;
  color: var(--star);
  opacity: 0.92;
}
.bp-empty { margin-top: 24px !important; color: var(--dust) !important; }

/* the "coming soon" note when it sits inside the panel */
.book-panel .soon-toast { z-index: 5; }

@media (max-width: 560px) {
  .book-panel {
    width: 100%;
    max-width: 100%;
    height: calc(100% - 24px);
    max-height: none;
    margin: auto 0 0;
    border-width: 1px 0 0;
    border-radius: 18px 18px 0 0;
  }
  .bp-scroll { padding: 26px 18px calc(30px + env(safe-area-inset-bottom, 0px)); }
  .bp-head { grid-template-columns: 104px 1fr; gap: 16px; padding-inline-end: 30px; }
  .bp-title { font-size: 1.45rem; }
  .bp-actions .bp-btn { flex: 1 1 0; padding: 0 12px; white-space: nowrap; }
}

/* opening and closing the search and the book panel (ui.js / book-panel.js add .is-closing) */
@media (prefers-reduced-motion: no-preference) {
  .search[open] { animation: dlg-drop var(--t-mid) var(--ease-out); }
  .book-panel[open] { animation: dlg-rise 0.36s var(--ease-out); }
  .search[open]::backdrop,
  .book-panel[open]::backdrop { animation: dlg-fade var(--t-mid) var(--ease-out); }
  .search[open].is-closing,
  .book-panel[open].is-closing { animation: dlg-out var(--t-fast) var(--ease) forwards; }
  .search[open].is-closing::backdrop,
  .book-panel[open].is-closing::backdrop { animation: dlg-fade var(--t-fast) var(--ease) reverse forwards; }
}
/* on phones the book panel is a sheet that slides up from the bottom */
@media (prefers-reduced-motion: no-preference) and (max-width: 560px) {
  .book-panel[open] { animation: dlg-sheet 0.4s var(--ease-out); }
  .book-panel[open].is-closing { animation: dlg-sheet-out 0.24s var(--ease) forwards; }
  .search[open] { animation: dlg-fade var(--t-mid) var(--ease-out); }
}

/* ---------- speed: on phones the panel and search fill the screen, so the
   costly blur behind them is almost invisible; a slightly deeper tint replaces it ---------- */
@media (max-width: 560px) {
  .book-panel::backdrop,
  .search::backdrop {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: rgba(7, 6, 24, 0.74);
  }
}

/* ---------- moving between pages, themes and levels ----------
   Pages fade into each other instead of flashing white (browsers that
   can't do this simply change page as before). The header stays put. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }
  html {
    scroll-behavior: smooth;
  }
}

.site-header {
  view-transition-name: site-header;
}

.chat-launch {
  view-transition-name: chat-launch;
}

::view-transition-old(root) {
  animation: vt-fade-out 0.2s var(--ease) both;
}

::view-transition-new(root) {
  animation: vt-fade-in 0.34s var(--ease-out) both;
}

@keyframes vt-fade-out {
  to { opacity: 0; }
}

@keyframes vt-fade-in {
  from { opacity: 0; }
}

/* the light/dark switch spreads out from its button (ui.js runs the circle) */
html.vt-theme::view-transition-old(root),
html.vt-theme::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

html.vt-theme::view-transition-new(root) {
  z-index: 2;
}

html.vt-theme .site-header,
html.vt-theme .chat-launch {
  view-transition-name: none;
}

/* shelves coming back into view after picking a level */
.shelf.is-entering {
  animation: shelf-in 0.46s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 55ms);
}

@keyframes shelf-in {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
}
