@import url("../_fonts/bbb-poppins-tn/stylesheet.css");

/* ─── Theme tokens ────────────────────────────────────────────────────────── */
/* Dark theme — default */
:root {
  --bg:     #22002b;
  --fg:     #ffffff;
  --link:   #ffffff;
  --hr:     rgba(255, 255, 255, 0.4);
  --accent: #aa00d4;   /* logo purple: emergency message bar */
  --gutter: 2rem;   /* side padding of the page; full-width bars cancel it */
  --sep:    0.6rem; /* space on each side of the "|" separator in menus */
}

/* Light theme */
:root[data-theme="light"] {
  --bg:     #f5f0f7;
  --fg:     #1a001f;
  --link:   #5a006e;
  --hr:     rgba(90, 0, 110, 0.25);
}

/* ─── CSS Reset (Josh Comeau) ─────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0; /* ADDED BY LH */
  border: 0; /* ADDED BY LH */
}

body {
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* Japanese: break lines between phrases, not inside words (Chromium; ignored elsewhere) */
:lang(ja) {
  word-break: auto-phrase;
}

#root, #__next {
  isolation: isolate;
}

script { /* ADDED BY LH */
  display: none;
}

/* ─── Base styles ─────────────────────────────────────────────────────────── */
body {
  background-color: var(--bg);
  color: var(--fg);
  font-family: "bbb-poppins-tn", sans-serif;
  padding: 0 var(--gutter) 2rem;
  margin-bottom: 8rem;
  transition: background-color 0.2s, color 0.2s;
}

a {
  color: var(--link);
}
/* Every link gets a wavy underline on hover, including those that are not underlined
   otherwise (site title, organisation name, current page). Wavy, because solid means
   "link" and dotted means "the section you are in" in the menus. !important because
   those rules are more specific. */
a:hover {
  text-decoration: underline wavy !important;
  text-underline-offset: 0.2em;
}
a[href^="http"]:not([href^="https://mutualpsychosocial.support"])::after {
  content: " ⧉";
  font-style: normal;
  text-decoration: none;
  display: inline-block; /* keeps it from being underlined with the link text */
}

h1, h2, h3 {
  font-family: "bbb-poppins-tn-display", sans-serif;
  margin: 1.2em 0 0.8em;
}
h1 {
  margin-top: 0;
}
p {
  margin-top: 1.5em;
  text-align: start;
}
small > span { /* the licence name (CC BY-SA 4.0) stays on one line */
  white-space: nowrap;
}

/* ─── Accessibility helpers ───────────────────────────────────────────────── */
/* Visually hidden, but still read by assistive technologies:
   - the theme checkbox (the label next to it is what the visitor sees),
   - the heading of the section that contains the articles,
   - the "(opens in a new tab)" notice added to external links (.visually-hidden). */
#theme-toggle,
main > section:has(> article) > h2,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
#theme-toggle:focus-visible + label,
a:focus-visible,
button:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

/* Skip link (inside the <div role="navigation"> directly in <body>, so that it is
   not outside every landmark): off-screen until it receives keyboard focus */
body > div > a {
  position: absolute;
  inset-inline-start: 0.5rem;
  top: -10rem;
  z-index: 20;
  padding: 0.5rem 1rem;
  background-color: var(--bg);
  color: var(--fg);
}
body > div > a:focus {
  top: 0.5rem;
}

/* ─── Emergency message (the <aside> directly in <body>) ──────────────────── */
/* One line at the very top, full-width, scrolls away with the page. The dismiss
   button is revealed by page.js; once dismissed, the attribute set on <html>
   (by theme-init.js on later pages, before first paint) hides the bar until the
   message id changes. */
body > aside {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 calc(-1 * var(--gutter));
  padding: 0.4rem 0.75rem; /* narrower than the gutter: keeps a short message on one line on a phone */
  background-color: var(--accent);
  color: #ffffff;
  font-size: 0.9rem;
}
body > aside p {
  flex: 1;
  min-width: 0;
  margin: 0;
  text-align: center;
}
body > aside a {
  color: inherit;
}
:root[dir="rtl"] body > aside {
  --dir: -1; /* the scrolling message starts on the right */
}

/* A message too long for the bar scrolls instead of wrapping (page.js sets
   data-scroll and --duration). It rests at each end,
   slides to the other, and back; hover or keyboard focus pauses it. With
   reduced motion nothing moves and the message wraps onto several lines.
   data-measure is set by page.js for an instant, to measure the text on one line. */
@media (prefers-reduced-motion: no-preference) {
  body > aside[data-measure] p {
    white-space: nowrap;
  }
  body > aside[data-scroll] p {
    overflow: hidden;
    white-space: nowrap;
    text-align: start;
  }
  body > aside[data-scroll] p span {
    display: inline-block;
    position: relative;
    animation: announcement-scroll var(--duration, 10s) ease-in-out infinite alternate;
  }
  body > aside[data-scroll]:hover p span,
  body > aside[data-scroll]:focus-within p span {
    animation-play-state: paused;
  }
}
/* The distance is computed by the browser from the real widths, never from a measured
   number that could go stale (web font arriving late, text zoom...): a percentage offset
   is relative to the bar's text area (W), a percentage translation to the message itself
   (M), and W - M is exactly how far the message must move to show its last character. */
@keyframes announcement-scroll {
  0%, 15%   { inset-inline-start: 0;    transform: none; }
  85%, 100% { inset-inline-start: 100%; transform: translateX(calc(-100% * var(--dir, 1))); }
}
body > aside button {
  background: none;
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 0.25rem;
  cursor: pointer;
}
:root[data-announcement="dismissed"] body > aside {
  display: none;
}

/* ─── Site header (landmark: body > header) ───────────────────────────────── */
/* Scrolls away with the page: it holds the site name, the language list and
   the Day/Night toggle. Only the primary navigation (below) stays on screen,
   which keeps the fixed part small on a phone.
   No media queries: the browser decides from the actual content widths.
   - Everything fits on one line: site name at the start, language list and
     Day/Night toggle at the end.
   - Otherwise the language list and toggle wrap onto a line ABOVE the site
     name (wrap-reverse), still aligned to the end.
   - If the site name alone is wider than the screen, it wraps onto several
     lines. */
body > header {
  display: flex;
  flex-wrap: wrap-reverse;
  align-items: center;
  gap: 0.25rem 0.75rem;
  padding-top: 0.5rem;
}

body > header > p { /* the site title: logo + site name */
  min-width: 0; /* lets the site name wrap instead of overflowing */
  margin: 0;
  font-family: "bbb-poppins-tn-display", sans-serif;
  font-size: 1.5rem;
}
body > header > p > a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--fg);
  text-decoration: none;
}
body > header > p img {
  flex-shrink: 0; /* keep the logo from shrinking; the site name must be free to wrap */
  width: 2.5rem;
  height: 2.5rem;
}

/* ─── Tools: language switcher + Day/Night toggle ─────────────────────────── */
body > header > nav { /* language switcher */
  margin-inline-start: auto; /* end of the row (right in LTR, left in RTL) */
  font-size: 0.85rem;
}
body > header > nav a {
  white-space: nowrap;
}

/* Language list: items are told apart by spacing alone (links are underlined,
   the current language is not), so a wrapped line can never start or end with
   a dangling separator. `gap` is the only spacing, whatever the direction. */
body > header > nav ul {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.9em;
  list-style: none;
}

label[for="theme-toggle"] {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--link);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  transition: color 0.2s;
}
label[for="theme-toggle"] span {
  text-decoration: underline;
}
/* Same hover effect as the links: the label acts as one */
label[for="theme-toggle"]:hover span {
  text-decoration: underline wavy;
  text-underline-offset: 0.2em;
}

/* The label holds two spans: the first (shown in the dark theme) and the last
   (shown in the light theme). It shows the TARGET theme (where clicking will
   take you):
   currently dark → ☾ + day label  |  currently light → ☀ + night label.
   The icon is larger than the text so it also acts as the visual separator
   between the language list and the switch. */
label[for="theme-toggle"]::before {
  content: "☾";
  font-size: 1.75em;
  line-height: 1;
  text-decoration: none;
}
:root:not([data-theme="light"]) label[for="theme-toggle"] span:last-child,
:root[data-theme="light"] label[for="theme-toggle"] span:first-child {
  display: none;
}
:root[data-theme="light"] label[for="theme-toggle"]::before {
  content: "☀";
}

/* ─── Navigation bars (primary + secondary) ───────────────────────────────── */
/* The primary navigation (the <nav> directly in <body>) is the sticky bar: the header above it scrolls away,
   it stays at the top. When a secondary navigation exists, it is the <nav>
   nested inside the primary one, so both stick together as one block whose height follows
   the content (no hard-coded offsets). The bar is full-width (the page gutter
   is cancelled); the rule under it is page-width. */
body > nav {
  --logo: 1.5rem;   /* size of the home (logo) item */
  position: sticky;
  top: 0;
  z-index: 10;
  margin: 0.75rem calc(-1 * var(--gutter));
  padding: 0.5rem var(--gutter) 0.75rem;
  background-color: var(--bg);
  transition: background-color 0.2s;
}
body > nav::after {
  content: "";
  position: absolute;
  inset-inline: var(--gutter);
  bottom: 0;
  border-bottom: 2px solid var(--hr);
}
body > nav > nav {
  margin-top: 0.5rem;
}

body > nav ul,
body > footer > nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0;
}

body > nav li + li::before,
body > footer > nav li + li::before {
  content: "|";
  margin: 0 var(--sep);
  opacity: 0.4;
  color: var(--fg);
}

body > nav a,
body > footer > nav a {
  color: var(--fg);
}
body > nav > nav a {
  font-size: 0.8rem;
}

/* "Reset my preferences": a button (it acts, it does not lead anywhere) that looks like the
   other footer links. Its list item is revealed by page.js only while something is stored. */
body > footer > nav button {
  background: none;
  color: var(--fg);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}
body > footer > nav button:hover {
  text-decoration: underline wavy;
  text-underline-offset: 0.2em;
}

/* The page the visitor is on is not underlined; so is the current language. */
nav a[aria-current="page"] {
  text-decoration: none;
}
/* The section the visitor is in (e.g. Trainings, while on one of its sub-pages)
   is still a link, to the section's own page: dotted instead of solid underline */
nav a[aria-current="true"] {
  text-decoration: underline dotted;
  text-underline-offset: 0.2em;
}

/* ─── Home item (logo) of the primary navigation ──────────────────────────── */
/* First item of the primary menu: the logo, linking to the welcome page in the current
   language. It is the way back "home" once the header (logo + site name) has
   scrolled away, so it is revealed progressively while the header leaves the
   screen, and collapsed (zero width) while the header is visible.
   Pure CSS, using a scroll-driven animation on the header's position.
   Browsers without support, or keyboard focus on the item, simply show it. */
body > nav > ul > li:first-child {
  margin-inline-end: var(--sep);
}
body > nav > ul > li:first-child img {
  width: var(--logo);
  height: var(--logo);
  max-width: none;
}
/* The logo replaces the separator that would otherwise follow it */
body > nav > ul > li:first-child + li::before {
  content: none;
}

@supports (animation-timeline: view()) {
  body {
    timeline-scope: --site-header;
  }
  body > header {
    view-timeline: --site-header block;
  }
  body > nav > ul > li:first-child {
    overflow: hidden;
    animation: nav-home-reveal linear both;
    animation-timeline: --site-header;
    animation-range: exit 0% exit 100%; /* from the header starting to leave, to it being gone */
  }
  body > nav > ul > li:first-child:focus-within {
    animation: none;
    overflow: visible; /* keep the focus outline visible */
  }
}

@keyframes nav-home-reveal {
  from { max-width: 0; margin-inline-end: 0; opacity: 0; }
  to   { max-width: var(--logo); margin-inline-end: var(--sep); opacity: 1; }
}

/* ─── Main content ────────────────────────────────────────────────────────── */
main {
  padding-top: 0.75rem;
}
main > section + section,
main > section + p {
  margin-top: 2rem;
}

/* Articles grid: the section that contains the articles. No media queries: as
   many columns as fit (each at least 16rem wide), sharing the width equally.
   The section's visually hidden h2 is out of flow, so it takes no grid cell. */
main > section:has(> article) {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(16rem, 100%), 1fr));
  gap: 1.5rem 2rem;
}

article {
  padding: 1rem 1.25rem;
  border: 1px solid var(--hr);
  border-start-end-radius: 1.5rem; /* top corner at the end of the line: top-right in LTR, top-left in RTL (Urdu) */
}
/* Optional picture above the title: decorative (empty alt), full-bleed at the top of the
   card, cropped to a fixed ratio so that all cards line up whatever the picture. The ratio
   is set here, so the space is reserved before the picture has loaded. The rounded corner
   of the card is repeated on the picture (1px less: the card's border). The picture is a
   link to the same page as the title; it is a mouse/touch shortcut only (the title is the
   link for keyboards and screen readers), so it shows no wavy underline on hover. */
article > header > a:has(> img) {
  display: block;
}
article > header > a:has(> img):hover {
  text-decoration: none !important;
}
article > header img {
  width: calc(100% + 2.5rem);
  max-width: none;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  margin: -1rem -1.25rem 1rem;
  border-start-end-radius: calc(1.5rem - 1px);
}
article h3 {
  margin: 0;
  font-weight: normal;
  font-size: 1.5rem;
}
article > p {
  margin-top: 0.8em;
}

/* ─── Site footer (landmark: body > footer) ───────────────────────────────── */
body > footer {
  margin-top: 2rem;
  padding-top: 0.5rem;
  border-top: 2px solid var(--hr);
}
body > footer > p:first-of-type > a:first-child { /* organisation name */
  font-size: larger;
  text-decoration: none;
}
