/* zakaria-elhoubba.com: shared styles. Black and white line drawings, a few leaves in the green of
   the Prophet's dome, Gentium for reading, Inter for small labels. */

:root {
  --ink: #111111;
  --muted: #6F6E68;
  --faint: #B4B2AC;
  --hair: rgba(17, 17, 17, 0.14);
  --bg: #FFFFFF;
  --dome: #2E7D4E;
  --sans: Inter, system-ui, -apple-system, sans-serif;
  --serif: 'Gentium Plus', Georgia, 'Times New Roman', serif;
  --arabic: Amiri, 'Noto Naskh Arabic', serif;
  --spring: cubic-bezier(.28, 1.4, .36, 1);
  --settle: cubic-bezier(.22, 1, .36, 1);
}

/* Rabat by Youssef Jabri (2010), "may be used freely": served unchanged from assets/fonts. */
@font-face { font-family: 'Rabat'; src: url('fonts/Rabat.otf') format('opentype'); font-display: swap; }

* { box-sizing: border-box; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: var(--serif); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }

.brand { position: absolute; left: 40px; top: 32px; z-index: 2; font-size: 19px; letter-spacing: -0.005em; }

/* ---------- the page menu: a column of short lines on the right ---------- */

.lines {
  position: fixed; right: 16px; top: 50%; transform: translateY(-50%); z-index: 3;
  display: flex; flex-direction: column; align-items: flex-end;
  padding: 6px 8px 6px 0; border-radius: 14px;
  transition: background-color .16s;
}
.lines:hover, .lines:focus-within, .lines.open {
  background: rgba(255, 255, 255, 0.72);
  -webkit-backdrop-filter: blur(10px) saturate(1.5); backdrop-filter: blur(10px) saturate(1.5);
}
.lines a {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  height: 30px; padding-left: 16px; color: var(--faint);
  transition: color .16s;
}
.lines .bar {
  display: block; width: 16px; height: 1.5px; border-radius: 2px; background: currentColor;
  transition: width .22s var(--spring);
}
.lines .label {
  font-family: var(--sans); font-size: 12px; font-weight: 500; letter-spacing: .01em; white-space: nowrap;
  opacity: 0; transform: translateX(6px); pointer-events: none;
  transition: opacity .14s, transform .22s var(--settle);
}
.lines a[aria-current="page"] { color: var(--ink); }
.lines a[aria-current="page"] .bar { width: 32px; height: 2px; }
.lines:hover .label, .lines:focus-within .label { opacity: .55; transform: none; }
.lines a:hover, .lines a:focus-visible, .lines a.is-lit { color: var(--ink); outline: none; }
.lines a:hover .bar, .lines a:focus-visible .bar, .lines a.is-lit .bar { width: 28px; }
.lines a:hover .label, .lines a:focus-visible .label, .lines a.is-lit .label { opacity: 1; transform: none; }
/* touch screens: only the lines show; the first tap opens the menu with its names (assets/lines.js) */
@media (hover: none) {
  .lines a { height: 40px; }
  .lines .label { opacity: 0; }
  .lines.open .label { opacity: 1; transform: none; }
  .lines.open a { color: var(--muted); }
  .lines.open a[aria-current="page"] { color: var(--ink); }
}

/* ---------- home: the good tree ---------- */

.home {
  position: relative; min-height: 100vh; min-height: 100svh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 72px 56px 88px;
  --day: 24s;
}
.home .tagline { position: absolute; left: 0; right: 0; bottom: 28px; margin: 0; text-align: center; font-family: var(--sans); font-size: 15px; color: var(--muted); }
/* the figure fills most of the height of the empty page (its drawing is 600 by 724) */
.scene { width: min(600px, 84vw, calc((100vh - 150px) * 0.829)); height: auto; display: block; overflow: visible; }
/* the verse runs along the lower half of the circle the sun and moon trace above */
.verse-arc { font-family: 'Rabat', var(--arabic); font-size: 36px; fill: var(--ink); }
.verse-arc-en { font-family: var(--sans); font-size: 12px; font-weight: 500; letter-spacing: .12em; fill: var(--muted); }
/* the verse appears word by word in reading order (fill-opacity, since opacity does not apply to a tspan) */
.word { animation: word .9s ease var(--d, 6s) both; }
@keyframes word { from { fill-opacity: 0; } to { fill-opacity: 1; } }
.verse { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.verse .ar { margin: 0; font-family: var(--arabic); font-size: 26px; line-height: 1.7; }
.verse .en { margin: 0; font-family: var(--sans); font-size: 12px; color: var(--muted); }

.el { cursor: pointer; outline: none; }
.hit { fill: transparent; }
.tag { opacity: 0; transition: opacity .2s; font-family: var(--sans); font-size: 14px; font-weight: 600; letter-spacing: .14em; fill: var(--ink); paint-order: stroke; stroke: #fff; stroke-width: 3px; stroke-linejoin: round; }
.el:hover .tag, .el:focus .tag, .el.is-lit .tag { opacity: 1; }
.ink { fill: var(--ink); }
.leaf { fill: var(--dome); }
.leaf-silver { fill: #86AD93; }
/* the sky: star-yellow pen dots, and the sun and moon as the letters ش and ق in discs */
.nuqta { fill: #E2B33C; }
.sun-disc { fill: #E3A92B; }
.moon-disc { fill: #FFFDF8; }
.moon-shadow { fill: #5E5B54; opacity: .55; }
.moon-ring { fill: none; stroke: #C9C6BC; stroke-width: 1.2; }
.roundel-letter { font-family: 'Rabat', var(--arabic); font-size: 26px; text-anchor: middle; dominant-baseline: central; }
.sun-letter { fill: #FFFFFF; }
.moon-letter { fill: #111111; }
.fruit-o { fill: #D9772B; }
.fruit-r { fill: #B5352B; }
.fruit-d { fill: #8E2A28; }

@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes bud { from { transform: scale(0); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes sway { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(3deg); } }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes unspin { from { transform: rotate(0deg); } to { transform: rotate(-360deg); } }
@keyframes stars { 0%, 48% { opacity: 0; } 60%, 90% { opacity: 1; } 97%, 100% { opacity: 0; } }
@keyframes wax { from { transform: translateX(-5px); } to { transform: translateX(-44px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* growth: a thin pen line writes each stroke (--d, --dur), the thick-and-thin shape inks in over it,
   then the pen line fades (--o). Plain stroke and opacity animations, so every browser draws them. */
@keyframes penout { to { opacity: 0; } }
@keyframes inkin { to { opacity: 1; } }
.pen { stroke: var(--ink); stroke-linecap: round; stroke-dasharray: 1; stroke-dashoffset: 1;
       animation: draw var(--dur, 1.2s) cubic-bezier(.45, 0, .2, 1) var(--d, 0s) forwards, penout .4s ease var(--o, 2s) forwards; }
.ink-in { opacity: 0; animation: inkin .5s ease-out var(--d, 0s) forwards; }
.dot { transform-box: fill-box; transform-origin: center; animation: bud .6s var(--spring) var(--d, 0s) both; }
/* each main limb sways a little once the tree has grown */
@keyframes limb { 0%, 100% { transform: rotate(0deg); } 50% { transform: rotate(var(--sw, 1deg)); } }
.limb { transform-box: view-box; transform-origin: var(--ox) var(--oy); animation: limb var(--sd, 7s) ease-in-out 6.5s infinite; }

/* the day: the sun and the moon turn around the tree once every --day */
.orbit { transform-box: view-box; transform-origin: 300px 430px; animation: spin var(--day) linear infinite; }
.sunc { transform-box: view-box; transform-origin: 0px 430px; animation: unspin var(--day) linear infinite; }
.moonc { transform-box: view-box; transform-origin: 600px 430px; animation: unspin var(--day) linear infinite; }
.star { opacity: 0; animation: stars var(--day) linear infinite; }
/* below the horizon the sun and the moon follow the dots down and sink into the first word of the verse,
   then rise again out of its last word (al-samāʾ, the sky). The percentages are points on the circle:
   the sun sets at 50%, sinks into كَلِمَةً between 54.6% and 58.3%, and comes out of السَّمَاءِ between 91.7% and 95.4%. */
/* the sky: light by day, warm at sunset (50%) and sunrise (0%), night blue while the moon is up */
.sky-dome { pointer-events: none; }
.dusk-sky { opacity: 0; animation: dusk var(--day) linear infinite; }
.night-sky { opacity: 0; animation: night var(--day) linear infinite; }
@keyframes dusk {
  0% { opacity: 1; }
  8%, 42% { opacity: 0; }
  50% { opacity: 1; }
  60%, 90% { opacity: 0; }
  100% { opacity: 1; }
}
@keyframes night {
  0% { opacity: .15; }
  5%, 46% { opacity: 0; }
  50% { opacity: .15; }
  58%, 92% { opacity: 1; }
  100% { opacity: .15; }
}
.sky-body { transform-box: view-box; animation: set-rise var(--day) linear infinite; }
.sun-body { transform-origin: 0px 430px; }
.moon-body { transform-origin: 600px 430px; animation-delay: calc(var(--day) * -0.5); }
@keyframes set-rise {
  0%, 54.6% { opacity: 1; transform: scale(1); }
  58.3%, 91.7% { opacity: 0; transform: scale(.35); visibility: hidden; }
  95.4%, 100% { opacity: 1; transform: scale(1); }
}
.shade { transform: translateX(-5px); animation: wax calc(var(--day) * 4) linear infinite; }

/* ---------- the pop-up book ----------
   A closed book lies on the page. Its cover lifts and the back page stands up with the sky printed on it;
   then two paper layers pop up from the fold: the circle with the verse, and in front of it the tree.
   --S is the book's width; everything else is measured from it. */

.home { padding: 56px 56px 72px; }
.stage {
  --S: min(560px, 86vw, calc((100svh - 120px) / 1.44));
  --paper: #F6F1E7;
  position: relative; width: var(--S); height: calc(var(--S) * 1.44);
  perspective: calc(var(--S) * 4.5); perspective-origin: 50% 0%;
}
.book {
  position: absolute; inset: 0; transform-style: preserve-3d;
  transform-origin: 50% 75%; transform: rotateX(var(--tx, 0deg)) rotateY(var(--ty, 0deg));
  transition: transform .9s var(--settle);
}
.page-back, .layer { position: absolute; bottom: calc(var(--S) * 0.36); transform-origin: 50% 100%; }
.page-back { left: 0; right: 0; height: calc(var(--S) * 1.08); transform-style: preserve-3d; }
.page-floor {
  position: absolute; left: 0; right: 0; top: calc(var(--S) * 1.08); height: calc(var(--S) * 1.08);
  transform-origin: 50% 0%; transform: rotateX(90deg);
  background: var(--paper); box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.12), inset 0 -6px 0 #E8E0CE;
}
.face { position: absolute; inset: 0; -webkit-backface-visibility: hidden; backface-visibility: hidden; border-radius: 2px 2px 0 0; }
.face-front { background: var(--paper); box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.12), inset 0 6px 0 #E8E0CE; }
.face-cover { background: #1F3D2D; transform: rotateX(180deg); box-shadow: inset 0 0 0 10px #1F3D2D, inset 0 0 0 11px #C9A24A; }
.layer { left: 9%; right: 9%; --z: 0px; transform: translateZ(var(--z)); }
.layer-verse { --z: calc(var(--S) * 0.05); }
.layer-tree { --z: calc(var(--S) * 0.1); }
.layer-art { display: block; width: 100%; height: auto; overflow: visible; pointer-events: none; }
.face-front .layer-art { position: absolute; left: 9%; width: 82%; bottom: 0; }
.layer-art .el { pointer-events: auto; }

@keyframes bookOpen { from { transform: rotateX(-87deg); } to { transform: rotateX(0deg); } }
@keyframes popUp {
  0% { transform: translateZ(var(--z)) rotateX(-89deg); }
  72% { transform: translateZ(var(--z)) rotateX(5deg); }
  100% { transform: translateZ(var(--z)) rotateX(0deg); }
}
.page-back { animation: bookOpen 1.5s var(--settle) .35s both; }
.layer-verse { animation: popUp 1.05s cubic-bezier(.3, .75, .3, 1) 1.1s both; }
.layer-tree { animation: popUp 1.05s cubic-bezier(.3, .75, .3, 1) 1.3s both; }
/* nothing on the pages moves until the book is open */
.home:not(.opened) .layer-art * { animation-play-state: paused; }

/* ---------- the pop-up book, opening sideways ----------
   The book lies on the table with its spine running away from the reader. The cover turns over the spine
   from right to left; the circle and then the tree rise across the fold, facing the reader.
   In the table's own plane, the origin is the middle of the spine; negative y is the far side. */

.stage.h {
  --S: min(820px, 94vw, calc(100svh - 120px));
  --P: calc(var(--S) * 0.46);
  --Hp: calc(var(--S) * 0.62);
  width: var(--S); height: calc(var(--S) * 0.98);
  perspective: calc(var(--S) * 2.8); perspective-origin: 50% -20%;
}
.table {
  position: absolute; left: 50%; top: 70%; width: 0; height: 0; transform-style: preserve-3d;
  transform: rotateX(calc(62deg + var(--tx, 0deg))) rotateZ(var(--ty, 0deg));
  transition: transform .9s var(--settle);
}
.hpage, .hleaf { position: absolute; left: 0; top: calc(var(--Hp) / -2); width: var(--P); height: var(--Hp); }
.hpage-right { background: var(--paper); box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.12), inset -6px 0 0 #E8E0CE; }
.hleaf { transform-origin: 0% 50%; transform-style: preserve-3d; transform: translateZ(1px) rotateY(-180deg); }
.hface { position: absolute; inset: 0; -webkit-backface-visibility: hidden; backface-visibility: hidden; }
.hface-cover { background: #1F3D2D; box-shadow: inset 0 0 0 10px #1F3D2D, inset 0 0 0 11px #C9A24A; }
.hface-inside { background: var(--paper); transform: rotateY(180deg); box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.12), inset 6px 0 0 #E8E0CE; }
.hpop { position: absolute; left: calc(var(--S) * -0.3); width: calc(var(--S) * 0.6); transform-origin: 50% 100%; transform: translateZ(2px) rotateX(-90deg); }
.hpop-circle { bottom: calc(var(--Hp) * 0.06); }
.hpop-tree { bottom: calc(var(--Hp) * 0.01); }

@keyframes hOpen { from { transform: translateZ(1px) rotateY(0deg); } to { transform: translateZ(1px) rotateY(-180deg); } }
@keyframes hPop {
  0% { transform: translateZ(2px) rotateX(0deg); opacity: 0; }
  12% { opacity: 1; }
  75% { transform: translateZ(2px) rotateX(-96deg); }
  100% { transform: translateZ(2px) rotateX(-90deg); opacity: 1; }
}
.hleaf { animation: hOpen 1.7s cubic-bezier(.6, 0, .25, 1) .4s both; }
.hpop-circle { animation: hPop 1.1s cubic-bezier(.3, .75, .3, 1) 1.15s both; }
.hpop-tree { animation: hPop 1.1s cubic-bezier(.3, .75, .3, 1) 1.35s both; }

/* ---------- inner pages ---------- */

.page { max-width: 720px; margin: 0 auto; padding: 136px 24px 96px; }

/* each inner page opens on its own part of the tree, drawn large and cut off by the top of the page;
   its lower edge fades into the page from --fade */
.part {
  height: clamp(240px, 30vw, 420px); overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 var(--fade, 80%), transparent);
  mask-image: linear-gradient(to bottom, #000 var(--fade, 80%), transparent);
}
.part svg { display: block; width: 100%; height: 100%; }
.part + .page { padding-top: 24px; }
.inner .brand {
  left: 28px; top: 22px; padding: 6px 12px; border-radius: 999px;
  background: rgba(255, 255, 255, .72); -webkit-backdrop-filter: blur(10px) saturate(1.5); backdrop-filter: blur(10px) saturate(1.5);
}

/* About: the sun and the moon cross the lower arc of their circle in turn. The sun is in sight for the first
   quarter of the day and the moon from 42% to 75%; the sky inside the circle follows them. */
.part-about { --aday: 40s; }
.a-orbit { transform-box: view-box; transform-origin: 720px -300px; animation: spin var(--aday) linear infinite; }
.a-sunc, .a-moonc { transform-box: view-box; animation: unspin var(--aday) linear infinite; }
.a-dusk { opacity: 0; animation: a-dusk var(--aday) linear infinite; }
.a-night { opacity: 0; animation: a-night var(--aday) linear infinite; }
.a-star { opacity: 0; animation: a-stars var(--aday) linear infinite; }
@keyframes a-dusk { 0%, 22% { opacity: 0; } 33% { opacity: 1; } 44%, 74% { opacity: 0; } 83% { opacity: 1; } 93%, 100% { opacity: 0; } }
@keyframes a-night { 0%, 27% { opacity: 0; } 42%, 74% { opacity: 1; } 87%, 100% { opacity: 0; } }
@keyframes a-stars { 0%, 36% { opacity: 0; } 46%, 72% { opacity: 1; } 80%, 100% { opacity: 0; } }
.page-head { display: flex; flex-direction: column; gap: 14px; margin-bottom: 48px; animation: rise .9s var(--settle) both; }
.eyebrow { font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0; font-size: 44px; line-height: 1.1; font-weight: 400; letter-spacing: -0.012em; }
.lede { margin: 0; font-size: 20px; line-height: 1.55; color: var(--muted); }
h2 { margin: 56px 0 10px; font-family: var(--sans); font-size: 12px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
h2:first-of-type { margin-top: 0; }

.list { display: flex; flex-direction: column; border-top: 1px solid var(--hair); }
.item { display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 20px; padding: 22px 0; border-bottom: 1px solid var(--hair); }
.item .meta { padding-top: 5px; font-family: var(--sans); font-size: 13px; color: var(--muted); }
.item .body { display: flex; flex-direction: column; gap: 4px; }
.item .title { font-size: 22px; line-height: 1.3; }
.item .sub { font-size: 17px; line-height: 1.5; color: var(--muted); }
a.item:hover .title { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }

.prose p { margin: 0 0 1em; font-size: 19px; line-height: 1.7; }

.site-foot { max-width: 720px; margin: 0 auto; padding: 0 24px 48px; font-family: var(--sans); font-size: 12px; color: var(--muted); }

/* ---------- small screens ---------- */

@media (max-width: 760px) {
  .brand { left: 24px; top: 24px; }
  .inner .brand { left: 12px; top: 14px; }
  .home { padding: 80px 48px; }
  .home .tagline { position: static; margin-top: 16px; }
  .page { padding: 96px 64px 72px 24px; }
  .site-foot { padding-right: 64px; }
  .lines { right: 8px; }
}
@media (max-width: 560px) {
  .item { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  h1 { font-size: 36px; }
}

/* ---------- reduced motion: show the grown tree and keep everything still ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .pen { opacity: 0; }
  .ink-in { opacity: 1; }
  .orbit { transform: rotate(55deg); }
  .sunc, .moonc { transform: rotate(-55deg); }
  .moon-body { visibility: hidden; }
}
