/* Parts every Grove page shares: the base, the paper grain, the mark, the top bar,
 * links and the language switcher. Every value comes from tokens.css. */

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }
body {
  color: var(--ink);
  background: var(--bg);
  font-family: var(--serif);
  font-size: var(--step-0);
  line-height: var(--leading);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:root:lang(zh) body { font-family: var(--serif-zh); }
:root:lang(ar) body { font-family: var(--serif-ar); }
/* Spaced letters break the joins of Arabic script and look loose in Chinese. */
:root:lang(ar) *, :root:lang(zh) h1 { letter-spacing: 0 !important; }
:root:lang(ar) h1 { line-height: var(--leading-snug); }

/* Paper grain over the whole page. */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* Links are underlined in the text colour and brighten to full ink. */
a {
  color: inherit;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.2em;
  text-decoration-color: currentColor;
  transition: color var(--duration-slow) var(--ease), text-decoration-color var(--duration-slow) var(--ease);
}

/* The mark: an olive branch that draws itself (mark.js). */
.mark {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: inherit;
  text-decoration: none;
  font-size: 1.05rem;
  letter-spacing: var(--tracking-label);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}
.mark svg { width: 3.5rem; height: 3.5rem; overflow: visible; }
.mark .ink { stroke: currentColor; stroke-width: 1.5; transition: opacity 0.5s; }
.mark.is-signing .ink { opacity: 0.22; }
.mark.is-fading .ink { opacity: 1; }
.mark .trace { fill: currentColor; stroke: none; }
.mark.is-fading .trace { opacity: 0; transition: opacity 0.7s ease-out; }

/* The top bar: the mark, then the way to the writing and the languages, all on bare ground. */
.top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2) clamp(1.25rem, 4vw, 2.75rem);
}
.nav { display: flex; align-items: center; gap: clamp(0.75rem, 2.5vw, 1.75rem); flex-wrap: wrap; }
.nav-link {
  font-size: 0.8rem;
  letter-spacing: var(--tracking-label);
  padding: 0.4rem 0.45rem;
  color: var(--faint);
  text-decoration-color: transparent;
  text-underline-offset: 0.3em;
}
.nav-link:hover, .nav-link:focus-visible, .nav-link[aria-current] { color: var(--ink); outline: none; }
.nav-link[aria-current] { text-decoration-color: currentColor; }

.langs { display: flex; align-items: center; gap: 0.15rem; }
.langs button {
  font: inherit;
  font-size: 0.8rem;
  letter-spacing: var(--tracking-label);
  padding: 0.4rem 0.45rem;
  border: 0;
  background: none;
  color: var(--faint);
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: transparent;
  text-decoration-thickness: var(--hairline);
  text-underline-offset: 0.3em;
  transition: color 0.35s var(--ease), text-decoration-color 0.35s var(--ease);
}
.langs button[lang="zh-Hans"] { font-family: var(--serif-zh); }
.langs button[lang="ar"] { font-family: var(--serif-ar); letter-spacing: 0; }
.langs button:hover, .langs button:focus-visible { color: var(--ink); outline: none; }
.langs button[aria-pressed="true"] { color: var(--ink); text-decoration-color: currentColor; cursor: default; }

/* Text written in several languages carries them all; the page hides all but the visitor's
 * (lang.js sets html[lang]). Only hiding, never showing, so each element keeps its own layout. */
:root:not(:lang(en)) [data-only="en"], :root:not(:lang(fr)) [data-only="fr"], :root:not(:lang(it)) [data-only="it"],
:root:not(:lang(zh)) [data-only="zh"], :root:not(:lang(ar)) [data-only="ar"] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
  a, .mark .ink, .langs button { transition: none; }
}
