/* Noor & Calm — fonts, reset, base elements, Arabic text, night motif,
   app shell (bottom bar on phones, sidebar on laptops). */

/* Cormorant Garamond (headings), Inter (body) and Amiri (Arabic only), all self-hosted.
   SIL Open Font License 1.1: assets/fonts/OFL-*.txt */
@font-face {
  font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 500 600; font-display: swap;
  src: url("../assets/fonts/cormorant-garamond-latin.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+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Cormorant Garamond'; font-style: normal; font-weight: 500 600; font-display: swap;
  src: url("../assets/fonts/cormorant-garamond-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 400 600; font-display: swap;
  src: url("../assets/fonts/inter-latin.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+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Inter'; font-style: normal; font-weight: 400 600; font-display: swap;
  src: url("../assets/fonts/inter-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Amiri only covers Arabic here, so Latin text never falls into it by accident. */
@font-face {
  font-family: 'Amiri'; font-style: normal; font-weight: 400; font-display: swap;
  src: url("../assets/fonts/amiri-arabic-400.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}
@font-face {
  font-family: 'Amiri'; font-style: normal; font-weight: 700; font-display: swap;
  src: url("../assets/fonts/amiri-arabic-700.woff2") format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC;
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100dvh;
  background: transparent; /* html paints --bg, so the motif layer (z-index -1) shows through */
  color: var(--text);
  font: 400 var(--fs-md)/var(--lh) var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
img, svg, canvas { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); text-underline-offset: 3px; }
h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 600; line-height: 1.15; letter-spacing: 0; font-variant-numeric: lining-nums; }
h1 { font-size: var(--fs-title); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
p, ul, ol { margin: 0; }
ul, ol { padding: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[tabindex="-1"]:focus { outline: none; }

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

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 100;
  padding: 8px 14px; border-radius: var(--r-pill);
  background: var(--button-bg); color: var(--on-button); font-weight: 500; text-decoration: none;
}
.skip-link:focus { top: calc(12px + var(--safe-t)); }

.icon { width: var(--icon); height: var(--icon); flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

/* ---------- demo banner ---------- */
body.has-demo { --demo-h: 32px; }
.demo-banner {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: center; gap: var(--s-5);
  min-height: var(--demo-h); padding: 4px var(--gutter); padding-top: calc(4px + var(--safe-t));
  background: var(--button-bg); color: var(--on-button);
  font-size: var(--fs-sm); text-align: center;
}
.demo-banner a { color: inherit; font-weight: 600; }

/* ---------- app shell ---------- */
.shell { min-height: calc(100dvh - var(--demo-h)); }
.main {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: calc(var(--s-6) + var(--safe-t)) var(--gutter) calc(var(--tabbar-h) + var(--safe-b) + var(--s-8));
}
body.has-demo .main { padding-top: var(--s-6); }
.main:focus { outline: none; }

/* bottom bar (phone) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding: 0 4px var(--safe-b);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-width: 0; padding: 0; border: 0; background: none;
  color: var(--text-muted); font-size: var(--fs-2xs); font-weight: 500; text-decoration: none;
}
.tab .icon { width: var(--icon-nav); height: var(--icon-nav); }
.tab[aria-current="page"] { color: var(--primary-strong); font-weight: 600; }
.tab[aria-current="page"] .icon { stroke-width: 2; }
.tab span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* sidebar (laptop) */
.sidebar { display: none; }

@media (min-width: 860px) {
  .shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .tabbar { display: none; }
  .main { padding: var(--s-8) var(--s-8) var(--s-10); }
  .sidebar {
    position: sticky; top: var(--demo-h);
    display: flex; flex-direction: column; gap: 2px;
    height: calc(100dvh - var(--demo-h)); overflow-y: auto;
    padding: var(--s-7) var(--s-4) var(--s-6);
    background: var(--surface); border-right: 1px solid var(--line);
  }
  .brand { display: flex; align-items: center; gap: var(--s-3); padding: 0 var(--s-3) var(--s-7); color: var(--text); text-decoration: none; }
  .brand img { width: 32px; height: 32px; border-radius: 9px; }
  .brand strong { display: block; font-family: var(--font-display); font-size: 21px; font-weight: 600; line-height: 1.1; }
  .brand small { display: block; font-size: var(--fs-xs); color: var(--text-muted); }
  .side-link {
    display: flex; align-items: center; gap: var(--s-4);
    height: 34px; padding: 0 var(--s-4); border-radius: var(--r-sm);
    color: var(--text-muted); font-size: 13px; font-weight: 500; text-decoration: none;
  }
  .side-link[aria-current="page"] { background: var(--surface-2); color: var(--primary-strong); font-weight: 600; }
  .side-sub { height: 30px; padding-left: calc(var(--s-4) + 4px); font-size: 12.5px; }
  .side-label { margin: var(--s-6) var(--s-4) var(--s-2); font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
}
@media (hover: hover) and (min-width: 860px) {
  .side-link:not([aria-current="page"]):hover { background: var(--surface-3); color: var(--text); }
}

.app-footer {
  margin-top: var(--s-10);
  padding-top: var(--s-5);
  border-top: 1px dashed var(--line-strong);
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-align: center;
}
.app-footer p + p { margin-top: 2px; }

.boot { display: grid; place-items: center; min-height: 70dvh; color: var(--text-muted); font-size: var(--fs-sm); }
.page-loading { display: flex; align-items: center; justify-content: center; gap: var(--s-4); min-height: 40dvh; color: var(--text-muted); font-size: var(--fs-sm); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--primary-soft); border-top-color: var(--primary-strong); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* ---------- Arabic text (Amiri, right-to-left) ---------- */
/* Always used as <p class="ar" lang="ar" dir="rtl">. Settings → "Arabic display: off" hides it. */
.ar {
  font-family: var(--font-arabic);
  font-size: var(--fs-arabic);
  font-weight: 400;
  line-height: 1.75;
  direction: rtl;
  unicode-bidi: isolate;
  text-align: right;
  color: var(--text);
}
.ar-lg { font-size: calc(var(--fs-arabic) * 1.35); text-align: center; }
.translit { font-size: var(--fs-sm); font-style: italic; color: var(--text-muted); }
.meaning { font-size: var(--fs-sm); color: var(--text); }
.source { font-size: var(--fs-xs); color: var(--text-muted); }
html[data-arabic="off"] .ar { display: none !important; }
html[data-translit="off"] .translit { display: none !important; }

/* ---------- crescent and stars behind the page ---------- */
/* Drawn with a mask so it takes the theme's --motif colour. Purely decorative. */
body::before {
  content: '';
  position: fixed; top: 0; right: 0; z-index: -1;
  width: min(560px, 120vw); height: min(560px, 120vw);
  background: var(--motif);
  opacity: var(--motif-opacity);
  pointer-events: none;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'%3E%3Cpath d='M318 70a96 96 0 1 0 54 150 78 78 0 1 1-54-150z'/%3E%3Cpath d='M238 62l5 13 13 5-13 5-5 13-5-13-13-5 13-5z'/%3E%3Cpath d='M150 128l3 8 8 3-8 3-3 8-3-8-8-3 8-3z'/%3E%3Cpath d='M210 250l3.5 9 9 3.5-9 3.5-3.5 9-3.5-9-9-3.5 9-3.5z'/%3E%3Ccircle cx='96' cy='60' r='2.5'/%3E%3Ccircle cx='180' cy='30' r='2'/%3E%3Ccircle cx='120' cy='220' r='2'/%3E%3Ccircle cx='280' cy='310' r='2.5'/%3E%3Ccircle cx='360' cy='330' r='2'/%3E%3Ccircle cx='60' cy='150' r='1.6'/%3E%3C/svg%3E") top right / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 400'%3E%3Cpath d='M318 70a96 96 0 1 0 54 150 78 78 0 1 1-54-150z'/%3E%3Cpath d='M238 62l5 13 13 5-13 5-5 13-5-13-13-5 13-5z'/%3E%3Cpath d='M150 128l3 8 8 3-8 3-3 8-3-8-8-3 8-3z'/%3E%3Cpath d='M210 250l3.5 9 9 3.5-9 3.5-3.5 9-3.5-9-9-3.5 9-3.5z'/%3E%3Ccircle cx='96' cy='60' r='2.5'/%3E%3Ccircle cx='180' cy='30' r='2'/%3E%3Ccircle cx='120' cy='220' r='2'/%3E%3Ccircle cx='280' cy='310' r='2.5'/%3E%3Ccircle cx='360' cy='330' r='2'/%3E%3Ccircle cx='60' cy='150' r='1.6'/%3E%3C/svg%3E") top right / contain no-repeat;
}
