:root {
  --green-1: #86bc24;
  --green-2: #008733;
  --green-3: #006532;
  --black: #001d25;
  --grey: #58595b;
  --grey-light: #f5f6f5;
  --white: #ffffff;

  --font: "Mulish", system-ui, sans-serif;
  --font-mono: "SF Mono", Monaco, Consolas, monospace;

  --sidebar-width: 15rem;
  --content-max: 44rem;
  /* Content column sits right of centre: more room on the left (margin art),
     less between content and sidebar. Never leaves under 2rem on the right. */
  --col-shift: clamp(0px, calc((100vw - var(--sidebar-width) - var(--content-max)) / 2 - 2rem), 4rem);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--black);
  background: var(--white);
}

/* Typography */
h1, h2, h3 {
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  /* Brand guidelines: IofC Green 01 for headings and the logo subline. */
  color: var(--green-1);
}

h1 {
  font-size: 2.25rem;
  margin-bottom: 1.5rem;
}

h2 {
  font-size: 1.5rem;
  margin-top: 3rem;
  margin-bottom: 1rem;
}

h3 {
  font-size: 1.125rem;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

p { margin-bottom: 1rem; }

a {
  color: var(--green-2);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.15s;
}

a:hover { color: var(--green-3); }

blockquote {
  border-left: 3px solid var(--green-1);
  padding-left: 1.25rem;
  margin: 1.5rem 0;
  color: var(--grey);
  font-style: italic;
}

hr {
  border: none;
  border-top: 1px solid #ddd;
  margin: 3rem 0;
}

ul, ol {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
}

li { margin-bottom: 0.35rem; }

img { max-width: 100%; height: auto; }

table { border-collapse: collapse; width: 100%; margin-bottom: 1.5rem; }
th, td { vertical-align: top; padding: 0.5rem 0.5rem 0.5rem 0.75rem; border: 1px solid #e8e8e8; text-align: left; }
th { font-weight: 700; background: var(--grey-light); }

/* Accent bar */
.accent-bar {
  height: 3px;
  background: linear-gradient(90deg, var(--green-3), var(--green-2), var(--green-1));
}

/* ─── Top bar (logo, desktop) ─── */

/* Same column as .site-body / .site-main, so the logo's left edge lines up
   with the left edge of the page content. */
.top-bar {
  margin-right: var(--sidebar-width);
  padding: 1.5rem 0;
}

.top-bar .site-logo {
  display: block;
  position: relative;
  left: var(--col-shift);
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 2.5rem;
  box-sizing: border-box;
}

.top-bar .site-logo img {
  display: block;
  height: 5rem;
  width: auto;
}

/* ─── Sidebar (desktop) ─── */

.sidebar {
  position: fixed;
  top: 3px;
  right: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--grey-light);
  border-left: 1px solid #e8e8e8;
  display: flex;
  flex-direction: column;
  padding: 2rem 1.5rem;
  z-index: 100;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-nav a {
  display: block;
  padding: 0.45rem 0.75rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--grey);
  text-decoration: none;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.sidebar-nav a:hover {
  color: var(--green-3);
  background: rgba(0, 101, 50, 0.06);
}

.sidebar-nav a.active {
  color: var(--green-3);
  background: rgba(0, 101, 50, 0.1);
}

.sidebar-nav a.sub,
.mobile-menu a.sub {
  font-size: 0.875rem;
  font-weight: 400;
}

.sidebar-nav a.sub.sub-2,
.mobile-menu a.sub.sub-2 {
  font-size: 0.8125rem;
}

.sidebar-bottom {
  margin-top: auto;
}

.sidebar .lang-switcher {
  display: flex;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
}

.logout-link {
  display: block;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--grey);
  text-decoration: none;
}

.logout-link:hover { color: var(--green-3); }

/* ─── Mobile header ─── */

.mobile-header {
  display: none;
  position: sticky;
  top: 3px;
  z-index: 100;
  background: var(--white);
  border-bottom: 1px solid #e8e8e8;
  padding: 0.75rem 1.25rem;
  align-items: center;
  justify-content: space-between;
}

.mobile-header .site-logo img {
  height: 3rem;
  width: auto;
}

.nav-mobile { position: relative; }

.nav-toggle-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 0.35rem 0.65rem;
  cursor: pointer;
  font-size: 1.25rem;
  color: var(--black);
  line-height: 1;
}

.mobile-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 200;
}

.mobile-menu {
  position: absolute;
  top: 0;
  right: 0;
  width: 16rem;
  height: 100%;
  background: var(--white);
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
}

.mobile-menu a {
  display: block;
  padding: 0.6rem 0.5rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--grey);
  text-decoration: none;
}

.mobile-menu a:hover {
  color: var(--green-3);
}

.mobile-menu .logout-link {
  margin-top: auto;
  padding: 0.75rem 0.5rem 0;
  font-size: 0.875rem;
}

.mobile-menu .logout-link + .lang-switcher { margin-top: 0; }

.mobile-menu .lang-switcher {
  margin-top: auto;
  display: flex;
  gap: 0.75rem;
  padding: 0.75rem 0.5rem;
  border-top: 1px solid #e8e8e8;
  font-size: 0.875rem;
  font-weight: 600;
}

/* ─── Content area ─── */

.site-body {
  margin-right: var(--sidebar-width);
  min-height: calc(100vh - 3px);
  display: flex;
  flex-direction: column;
}

.site-main {
  position: relative;
  left: var(--col-shift);
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 3rem 2.5rem 4rem;
  width: 100%;
  flex: 1;
}

/* Hero (homepage) */
.hero {
  padding: 4rem 0 3rem;
}

.hero h1 {
  font-size: 2.75rem;
  line-height: 1.15;
  max-width: 36rem;
}

/* The first paragraph after the hero heading continues it: same style, smaller */
.hero h1 + p {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--green-1);
  max-width: 36rem;
  margin-top: -0.5rem;
  margin-bottom: 2rem;
}

/* ─── Footer ─── */

.site-footer {
  border-top: 1px solid #e8e8e8;
  background: var(--grey-light);
}

.site-footer-inner {
  position: relative;
  left: var(--col-shift);
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 2rem 2.5rem;
}

.footer-org {
  font-size: 0.875rem;
  color: var(--grey);
  line-height: 1.4;
}

.footer-org strong {
  color: var(--black);
  font-weight: 700;
  display: block;
}

.pretitle {
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--black);
  margin-bottom: 0.5rem;
}

.footer-org-alt {
  display: block;
  font-size: 0.8rem;
  color: var(--grey);
  line-height: 1.4;
}

.footer-contact {
  display: inline-block;
  margin-top: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--green-3);
  text-decoration: none;
}

.footer-contact:hover {
  text-decoration: underline;
}

/* ─── Language switcher (shared) ─── */

.lang-switcher a,
.lang-switcher span {
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.35rem;
  border-radius: 3px;
}

.lang-switcher a { color: var(--grey); }
.lang-switcher a:hover { color: var(--green-3); }

.lang-switcher .active {
  color: var(--green-3);
  background: rgba(0, 135, 51, 0.08);
}

/* ─── Responsive ─── */

@media (max-width: 900px) {
  :root { --col-shift: 0px; }
  .top-bar { display: none; }
  .sidebar { display: none; }
  .mobile-header { display: flex; }
  .site-body { margin-right: 0; }
  .site-main { padding: 2rem 1.25rem 3rem; }
  .site-footer-inner { padding: 1.5rem 1.25rem; }
  h1 { font-size: 1.75rem; }
  h2 { font-size: 1.25rem; }
  .hero { padding: 2.5rem 0 2rem; }
  .hero h1 { font-size: 2rem; }
  .hero h1 + p { font-size: 1.25rem; }
}

/* Stack table rows on narrow screens so the last column is not cut off */
@media (max-width: 600px) {
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr { border: 1px solid #e8e8e8; margin-bottom: 1rem; padding: 0.25rem 0; }
  td { border: 0; padding: 0.25rem 0.75rem; }
  td:nth-child(2)::before { content: "\2192\00a0"; font-weight: 400; }
}

/* Page audio (components/page-audio.tsx) */
.page-audio {
  margin: 0 0 2rem;
  padding: 0.875rem 1rem 0.75rem;
  background: var(--grey-light);
  border-left: 3px solid var(--green-2);
  border-radius: 0 4px 4px 0;
}
.page-audio-head {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  margin-bottom: 0.5rem;
}
.page-audio-title {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--green-3);
}
.page-audio-length {
  font-size: 0.8125rem;
  color: var(--grey);
}
.page-audio audio {
  display: block;
  width: 100%;
  height: 2.5rem;
}
.page-audio-note {
  margin: 0.375rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--grey);
}
.page-audio-draft {
  border-left-color: #c77d00;
  background: #fff7e6;
}
.page-audio-draft .page-audio-title,
.page-audio-draft .page-audio-note { color: #8a5600; }

/* Page audio placed after the second paragraph, as an illustration in the flow.
   The body sits in nested wrapper divs; `display: contents` on those makes the
   article's blocks and the player siblings in one flex column, so `order` can
   put the player after the 2nd <p>. Visitors only: editors (who have a
   [data-dune-body] element) keep the player at the top. Pages with fewer than
   two paragraphs are untouched (player stays on top). */
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) {
  display: flex;
  flex-direction: column;
}
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > div:not(.page-audio),
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > div:not(.page-audio) > div,
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > div:not(.page-audio) > div > div {
  display: contents;
}
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > .page-audio {
  order: 1;
  margin: 0.75rem 0 1.5rem;
}
:is(article, .hero) > div:not(.page-audio) > div > div > p:nth-of-type(2) ~ * { order: 2; }
/* Flex does not collapse margins; take the previous block's 1rem off the larger top margins. */
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > div > div > div > h2 { margin-top: 2rem; }
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > div > div > div > h3 { margin-top: 1rem; }
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > div > div > div > blockquote { margin-top: 0.5rem; }
:is(article, .hero):not(:has([data-dune-body])):has(> div:not(.page-audio) > div > div > p:nth-of-type(2)) > div > div > div > hr { margin-top: 2rem; }

/* ─── Margin art (large screens): slow colour play in the left margin ─── */
/* Prototype. Two directions, picked with ?art=blobs | weave | off:
   blobs = translucent circles drifting and overlapping (Caux Forum),
   weave = bars sliding across each other (Réseaux Caux).
   Decorative only; transform-only animation; static under reduced motion. */

.margin-art { display: none; }

@media (min-width: 1280px) {
  .margin-art {
    display: block;
    position: fixed;
    top: 3px;
    bottom: 0;
    left: 0;
    width: calc((100vw - var(--sidebar-width) - var(--content-max)) / 2 + var(--col-shift));
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
    -webkit-mask-image: linear-gradient(to right, #000 50%, transparent 100%);
    mask-image: linear-gradient(to right, #000 50%, transparent 100%);
    filter: saturate(1.35);
  }
  html[data-art="off"] .margin-art { display: none; }

  .art { position: absolute; inset: 0; }
  html:not([data-art="weave"]) .art-weave,
  html[data-art="weave"] .art-blobs { display: none; }

  /* Blobs */
  .b {
    --s: 12rem; --x: 20%; --y: 10vh; --dx: 2rem; --dy: 3rem; --d: 36s; --c: var(--green-1);
    position: absolute;
    left: var(--x);
    top: var(--y);
    width: var(--s);
    height: var(--s);
    margin-left: calc(var(--s) / -2);
    border-radius: 50%;
    background: var(--c);
    opacity: 0.7;
    mix-blend-mode: multiply;
    animation: art-drift var(--d) ease-in-out infinite alternate;
    will-change: transform;
  }
  .b1 { --s: 15rem; --x: 15%; --y: 6vh;  --dx: 3rem;  --dy: 4rem;  --d: 34s; --c: #86bc24; }
  .b2 { --s: 10rem; --x: 55%; --y: 0vh;  --dx: -2rem; --dy: 3rem;  --d: 40s; --c: #007ac3; }
  .b3 { --s: 13rem; --x: 30%; --y: 22vh; --dx: 2.5rem;--dy: -3rem; --d: 31s; --c: #008733; }
  .b4 { --s: 9rem;  --x: 10%; --y: 40vh; --dx: 3rem;  --dy: 2rem;  --d: 38s; --c: #f0d400; }
  .b5 { --s: 11rem; --x: 60%; --y: 50vh; --dx: -3rem; --dy: -2rem; --d: 43s; --c: #4bbdcf; }
  .b6 { --s: 8rem;  --x: 35%; --y: 66vh; --dx: 2rem;  --dy: -4rem; --d: 36s; --c: #d9563a; }
  .b7 { --s: 10rem; --x: 8%;  --y: 76vh; --dx: 3rem;  --dy: -2rem; --d: 32s; --c: #ed7801; }
  .b8 { --s: 12rem; --x: 50%; --y: 86vh; --dx: -2rem; --dy: -3rem; --d: 41s; --c: #86bc24; }

  @keyframes art-drift {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(var(--dx), var(--dy)) scale(1.12); }
  }

  /* Weave */
  .art-weave { transform: rotate(-4deg) scale(1.25); }
  .w {
    --p: 20%; --t: 0s; --d: 32s; --m: 5rem; --c: var(--green-1);
    position: absolute;
    border-radius: 0.6rem;
    background: var(--c);
    opacity: 0.92;
    mix-blend-mode: multiply;
    will-change: transform;
  }
  .w.v { top: -10%; width: 1.1rem; height: 80%; left: var(--p); animation: art-slide-y var(--d) ease-in-out infinite alternate; }
  .w.h { left: -10%; height: 1.1rem; width: 120%; top: var(--p); animation: art-slide-x var(--d) ease-in-out infinite alternate; }
  .v1 { --p: 12%; --d: 30s; --m: 6rem;  --c: #d9563a; }
  .v2 { --p: 28%; --d: 38s; --m: -5rem; --c: #f0d400; }
  .v3 { --p: 44%; --d: 34s; --m: 7rem;  --c: #86bc24; }
  .v4 { --p: 60%; --d: 42s; --m: -6rem; --c: #008733; }
  .v5 { --p: 76%; --d: 32s; --m: 5rem;  --c: #4bbdcf; }
  .h1 { --p: 14%; --d: 36s; --m: 4rem;  --c: #007ac3; }
  .h2 { --p: 32%; --d: 31s; --m: -5rem; --c: #86bc24; }
  .h3 { --p: 50%; --d: 40s; --m: 6rem;  --c: #ed7801; }
  .h4 { --p: 68%; --d: 34s; --m: -4rem; --c: #008733; }
  .h5 { --p: 86%; --d: 38s; --m: 5rem;  --c: #d9563a; }

  @keyframes art-slide-y { from { transform: translateY(calc(var(--m) * -1)); } to { transform: translateY(var(--m)); } }
  @keyframes art-slide-x { from { transform: translateX(calc(var(--m) * -1)); } to { transform: translateX(var(--m)); } }
}

@media (prefers-reduced-motion: reduce) {
  .b, .w { animation: none; }
}

@media print { .margin-art { display: none; } }

/* ─── Access-code login (templates/login.tsx) ─── */

.code-form { margin: 2rem 0 1.5rem; }
.code-form label { display: block; font-weight: 700; margin-bottom: 0.5rem; }
.code-row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.code-row input {
  flex: 1 1 14rem;
  font: inherit;
  font-size: 1.125rem;
  letter-spacing: 0.05em;
  padding: 0.65rem 0.85rem;
  border: 1px solid #c9ccc9;
  border-radius: 4px;
  background: var(--white);
  color: var(--black);
}
.code-row input:focus { outline: 2px solid var(--green-2); outline-offset: 1px; border-color: var(--green-2); }
.code-row button {
  font: inherit;
  font-weight: 700;
  padding: 0.65rem 1.4rem;
  border: 0;
  border-radius: 4px;
  background: var(--green-2);
  color: var(--white);
  cursor: pointer;
}
.code-row button:hover { background: var(--green-3); }
.code-error { color: #b3261e; font-weight: 600; }
.code-teaser { margin-top: 3rem; padding-top: 0.5rem; border-top: 1px solid #e8e8e8; }
