/* Base: site-layer tokens (not brand), reset, typography, layout primitives, utilities.
   Logical properties only (inline/block), never left/right, so both directions work. */

:root {
    /* layout */
    --container: 1240px;
    --container-narrow: 760px;
    --gutter: clamp(16px, 1rem + 2vw, 40px);
    --section-y: clamp(36px, 1.25rem + 3.2vw, 72px); /* section rhythm: 72px desktop, ~40px phone */
    --header-h: 76px;
    --appbar-h: 60px;
    --tabbar-h: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    /* motion: short and calm, nothing moves on its own */
    --ease: cubic-bezier(.22, 1, .36, 1);
    --dur-1: 150ms;
    --dur-2: 260ms;
    /* layers */
    --z-raise: 2; --z-header: 100; --z-tabbar: 110; --z-layer: 200; --z-toast: 300;
    /* hairline on green bands */
    --line-on-dark: color-mix(in srgb, var(--fl-egg) 22%, transparent);
    --on-primary-soft: color-mix(in srgb, var(--fl-egg) 84%, var(--fl-green)); /* paragraph text on green: 5.12 */
}

/* ── reset ── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-padding-top: calc(var(--header-h) + 16px); }
body {
    margin: 0; min-height: 100vh;
    background: var(--paper); color: var(--ink);
    font: var(--fw-body) var(--fs-base)/var(--lh-body) var(--font-body);
    -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
:lang(ar) body, body:lang(ar) { line-height: var(--lh-body-ar); }
img, svg, video { display: block; max-width: 100%; }
img { height: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
h1, h2, h3, h4, p, ul, ol, figure, blockquote { margin: 0; }
ul[class], ol[class] { list-style: none; padding: 0; }
[hidden] { display: none !important; }
main { overflow-x: clip; } /* tilted bands (ribbon) run past the edges */

/* ── typography ── */
h1, h2, h3, h4 {
    font-family: var(--font-display); font-weight: var(--fw-heavy);
    line-height: 1.1; color: var(--primary); text-wrap: balance;
}
:lang(en) :is(h1, h2) { line-height: var(--lh-display); letter-spacing: var(--tracking-caps); }
h1 { font-size: var(--fs-hero); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); font-family: var(--font-body); }
h4 { font-size: var(--fs-lg); font-family: var(--font-body); }
p { text-wrap: pretty; }
strong, b { font-weight: var(--fw-bold); }
small { font-size: var(--fs-sm); }
.fl-hand { font-family: var(--font-hand); font-style: italic; font-weight: 400; }
.fl-num, .fl-money { unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
.fl-money { white-space: nowrap; }

/* ── icons ── */
.fl-icon { width: 1.25em; height: 1.25em; flex: none; display: inline-block; vertical-align: -0.25em; }
[dir="rtl"] .fl-flip { transform: scaleX(-1); }

/* ── layout primitives ── */
.fl-wrap { width: 100%; max-width: calc(var(--container) + 2 * var(--gutter)); margin-inline: auto; padding-inline: var(--gutter); }
.fl-section { padding-block: var(--section-y); }
.fl-stack > * + * { margin-block-start: var(--s-4); }
.fl-cluster { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

/* ── focus & a11y ── */
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.fl-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.fl-skip { position: absolute; inset-inline-start: var(--s-3); inset-block-start: -100px; z-index: var(--z-toast); background: var(--surface); color: var(--primary); padding: var(--s-2) var(--s-4); border-radius: var(--r-pill); font-weight: var(--fw-bold); }
.fl-skip:focus { inset-block-start: var(--s-3); }
::selection { background: var(--fl-yellow); color: var(--fl-green); }

/* ── patterns (decorative backgrounds, never behind body text) ── */
.fl-pat-grid {
    background-image: linear-gradient(var(--pat-line, var(--line-on-dark)) 1px, transparent 1px),
                      linear-gradient(90deg, var(--pat-line, var(--line-on-dark)) 1px, transparent 1px);
    background-size: var(--grid-cell) var(--grid-cell);
}
/* the same grid fading out towards the bottom (footer, bands): lines never compete with what sits low */
.fl-pat-fade { position: relative; isolation: isolate; }
.fl-pat-fade::before {
    content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
    background-image: linear-gradient(var(--pat-line, var(--line-on-dark)) 1px, transparent 1px),
                      linear-gradient(90deg, var(--pat-line, var(--line-on-dark)) 1px, transparent 1px);
    background-size: var(--grid-cell) var(--grid-cell);
    -webkit-mask-image: linear-gradient(to bottom, #000, transparent 75%); mask-image: linear-gradient(to bottom, #000, transparent 75%);
}
.fl-pat-diamond { position: relative; isolation: isolate; }
.fl-pat-diamond::before {
    content: ""; position: absolute; inset: 0; z-index: -1; background: var(--pat-color, var(--accent));
    -webkit-mask: var(--tile-diamond) 0 0 / var(--tile-diamond-size) repeat; mask: var(--tile-diamond) 0 0 / var(--tile-diamond-size) repeat;
}

/* ── template-only chrome (tpl-*): never ported ── */
.tpl-doc { background: var(--paper); }
.tpl-main { max-width: 1200px; margin: 0 auto; padding: var(--s-6) var(--gutter) 120px; }
.tpl-main > h1 { font-size: var(--fs-2xl); margin-block-end: var(--s-2); }
.tpl-main > h1, .tpl-lead, .tpl-sec > h2, .tpl-sec > p { direction: ltr; text-align: left; } /* template chrome is English */
.tpl-lead { color: var(--ink-soft); margin-block-end: var(--s-6); }
.tpl-toc { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-block-end: var(--s-6); font-size: var(--fs-sm); }
.tpl-toc a { padding: 2px var(--s-3); border: 1px solid var(--line); border-radius: var(--r-pill); text-decoration: none; background: var(--surface); }
.tpl-sec { margin-block: var(--s-7); }
.tpl-sec > h2 { font-size: var(--fs-xl); margin-block-end: var(--s-2); }
.tpl-sec > p { color: var(--ink-soft); font-size: var(--fs-sm); margin-block-end: var(--s-4); }
.tpl-box { display: flex; flex-wrap: wrap; gap: var(--s-4); align-items: center; padding: var(--s-5); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r-md); }
.tpl-box + .tpl-box { margin-block-start: var(--s-3); }
.tpl-grid > .tpl-box { margin: 0; }
.tpl-box--col { flex-direction: column; flex-wrap: nowrap; align-items: stretch; }
.tpl-box--dark { background: var(--primary); border-color: transparent; }
.tpl-box--paper { background: var(--paper); }
.tpl-grid { display: grid; gap: var(--s-5); grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); width: 100%; }
.tpl-label { display: block; font: 600 11px/1.4 ui-monospace, Consolas, monospace; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .06em; margin-block-end: var(--s-2); direction: ltr; text-align: start; }
.tpl-swatch { display: grid; grid-template-rows: 88px auto; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line); background: var(--surface); font-size: var(--fs-sm); }
.tpl-swatch div:last-child { padding: var(--s-2) var(--s-3); }
.tpl-mails { display: flex; flex-wrap: wrap; gap: var(--s-6); align-items: flex-start; direction: ltr; }
.tpl-mails figure { margin: 0; display: grid; gap: var(--s-2); }
.tpl-mails figcaption { font: 600 11px/1.4 ui-monospace, Consolas, monospace; color: var(--ink-soft); text-transform: uppercase; }
.tpl-mails iframe { max-width: 100%; border: 1px solid var(--line); border-radius: var(--r-md); background: #fff; }
.tpl-swatch code { font: 12px ui-monospace, Consolas, monospace; direction: ltr; unicode-bidi: isolate; }
.tpl-pages { display: grid; gap: var(--s-2); grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.tpl-pages a { display: flex; justify-content: space-between; gap: var(--s-2); padding: var(--s-3) var(--s-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); text-decoration: none; font-weight: var(--fw-medium); }
.tpl-pages a:hover { border-color: var(--primary); }
.tpl-pages a.is-todo { opacity: .55; pointer-events: none; background: transparent; border-style: dashed; }
.tpl-pages small { color: var(--ink-soft); font-weight: 400; }
.tpl-bar { position: fixed; inset-block-end: calc(12px + var(--safe-bottom)); inset-inline-start: 50%; translate: -50% 0; display: flex; gap: 4px; padding: 6px; background: #1b1b1b; border-radius: 999px; font: 13px/1.4 system-ui, sans-serif; z-index: 999; box-shadow: 0 6px 24px rgba(0,0,0,.25); max-width: calc(100vw - 24px); overflow-x: auto; }
.tpl-bar a { color: #fff; text-decoration: none; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.tpl-bar a:hover { background: #333; }
.tpl-bar a.is-state { background: #3a3a3a; }
.tpl-bar a.is-on { background: #FCE615; color: #1b1b1b; }
.tpl-bar ~ .fl-toasts { translate: 0 -56px; } /* keep demo toasts clear of the review bar */
@media (max-width: 899px) { .tpl-bar { inset-block-end: calc(var(--tabbar-h) + 10px + var(--safe-bottom)); } .tpl-bar ~ .fl-toasts { translate: 0 -52px; } }
/* catalogue embeds (frame.php in an iframe): one frame part per page */
.tpl-embed { min-height: 0; }
.tpl-embed .fl-sheet { position: static; display: flex; flex-direction: column; margin: 0 auto; max-height: none; animation: none; }
.tpl-embed .fl-fabs { display: flex; gap: 12px; padding: 16px; }
.tpl-embed .fl-fab { position: static; }
.tpl-frames { display: grid; gap: var(--s-5); }
.tpl-frames--phones { grid-template-columns: repeat(auto-fill, 390px); justify-content: start; }
.tpl-iframe { display: block; width: 100%; height: 120px; border: 1px dashed var(--line); border-radius: var(--r-md); background: var(--paper); }
.tpl-iframe--phone { width: 390px; }
.tpl-embed .fl-mega { max-height: none; overflow: visible; }
html:has(.tpl-embed) { overflow: hidden; }

/* Arabic display type needs room above for diacritics (shadda, hamza): tight Latin leading made "جهّز" collide with the line above */
:lang(ar) :is(h1, h2, h3, .fl-title, .fl-hero__title, .fl-story__big, .fl-poster__big, .fl-poster__title, .fl-feat__name, .fl-buy__name, .fl-pagehead h1) { line-height: 1.32; }
/* the biggest Arabic display lines need more: stacked marks (shadda + fatha) meet the descenders of the line above */
:lang(ar) :is(.fl-hero__title, .fl-story__big, .fl-poster__big, .fl-pagehead h1, h1) { line-height: 1.55; }
:lang(ar) h1.fl-buy__name { line-height: 1.4; }
