/*
Theme Name: Black Combe Runners
Theme URI: https://bcrunners.org.uk
Description: Block child theme of Twenty Twenty-Five. Chrome (header, hero, skyline/fade, footer) lives in the theme's templates + this stylesheet; page bodies are core blocks in the Site Editor. Brand tokens are shared with theme.json.
Template: twentytwentyfive
Author: Black Combe Runners
Version: 1.2.0
Requires at least: 6.7
Tested up to: 7.0
Requires PHP: 8.5
Text Domain: bcr
*/

/* ---- Reset (condensed modern reset) ---------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100svh; line-height: 1.6; -webkit-font-smoothing: antialiased; }
img, picture, svg, video { display: block; max-width: 100%; height: auto; }
input, button, textarea, select { font: inherit; }
h1, h2, h3 { line-height: 1.1; text-wrap: balance; }
p { text-wrap: pretty; overflow-wrap: break-word; }
:target { scroll-margin-top: 5rem; }

@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* ---- Design tokens --------------------------------------------------- */
/* Colours mirror the theme.json palette (editor swatches); the literals here
   are the front-end source and keep the CSS working in any context. */
:root {
  /* System by default; light-dark() resolves each token to the active
     color-scheme. The footer control flips color-scheme via [data-theme]. */
  color-scheme: light dark;

  --ink:     light-dark(#0a0a0a, #eef2f0);
  --paper:   light-dark(#ffffff, #0e1210);
  --muted:   light-dark(#55605a, #9aa7a1);
  --surface: light-dark(#f4f6f5, #161b19);
  --border:  light-dark(#e2e6e4, #2a312e);

  --color-bcr: #27CFA2FF;
  --color-twitter: #000000;
  --color-facebook: #49669e;
  --color-instagram: #c13584;
  --color-iplayer: #e15896;
  --color-pinterest: #c93949;
  --color-linkedin: #0072B1;

  --accent: var(--color-bcr);
  --accent-dark: #15663a;
  --accent-on-dark: #8ff4b8;
  --link: light-dark(var(--accent-dark), var(--accent-on-dark));

  --content: 680px;   /* matches theme.json contentSize */
  --wide: 1180px;     /* matches theme.json wideSize */
  --gutter: clamp(1rem, 4vw, 2.5rem);
  --margin: 360px;
  --radius: 8px;

  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --step-title: clamp(3rem, 6vw, 4.5rem);
  --step-h2: clamp(1.5rem, 3vw, 2rem);
  --step-h3: clamp(1rem, 2vw, 1.5rem);
  --nav-font-size: 1.2rem;

  --icon-size: 1.2rem;
}

/* Colour-mode override — the footer control sets html[data-theme]; light-dark()
   above does the rest. No attribute = system (color-scheme: light dark). */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"]  { color-scheme: dark; }

/* ---- Base ------------------------------------------------------------ */

body {
  font-family: var(--font-sans);
  color: var(--ink);
  background: var(--paper);
}

/* The parent theme's global styles paint the page from its base/contrast presets
   and win on source order. Point those presets at our mode-aware tokens (and
   hard-win the body rule via :root specificity) so the page follows light/dark. */
:root {
  --wp--preset--color--base: var(--paper);
  --wp--preset--color--contrast: var(--ink);
}
:root body { background-color: var(--paper); color: var(--ink); }
/* Links use --link (mode-aware dark green) for AA contrast on paper; the bright
   brand --accent only fails as text (1.99:1), so it's reserved for the hover state. */
a { color: var(--link); text-underline-offset: 0.15em; }
a:hover { color: var(--accent); }

/* Content links follow the colour mode — theme.json pins them to the dark-green
   accent, which is unreadable on a dark background. */
.wp-block-post-content a,
.entry-content a { color: var(--link); }

p { margin: 0 0 1em 0; }

:where(a, button):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button {
  display: inline-block;
  padding: 0.7em 1.4em;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius);
  text-decoration: none;
  transition: background-color 150ms ease;
}
.button:hover { background: var(--accent-dark); color: #fff; }

svg.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}
svg.icon.filled { fill: currentColor; stroke: none; stroke-width: 0; }

h1.content-title {
  max-width: var(--content);
  margin-left: auto !important;
  margin-right: auto !important;
  font-weight: bold;
}

/* ---- Header (chrome) ------------------------------------------------- */

.header-wrapper {
  position: fixed;
  top: 0;
  width: 100%;
  transition: box-shadow 150ms ease;
  z-index: 100;
}

.site-header {
  width: min(100%, var(--wide));
  margin: 0 auto;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  padding: 1rem var(--gutter);
  color: var(--ink);
}

a.site-brand {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: var(--nav-font-size)
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: center;
}
.site-nav .mobile { display: none; }
.site-nav a {
  color: var(--paper);
  text-decoration: none;
  opacity: 0.9;
  font-size: var(--nav-font-size)
}
.site-nav a:hover { text-shadow: 0 0 10px var(--paper); opacity: 1; }
.site-nav span.socials { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.site-nav .theme-toggle { display: none }

.site-search {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
}
.site-search label {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  align-items: center;
  color: var(--paper);
  margin: 0;
}

.site-search input {
  border: none;
  background-color: transparent;
  color: var(--paper);
  text-align: right;
  padding: 0.25rem;
  width: 100px;
  font-size: var(--nav-font-size);
}

.site-search input::placeholder {
  color: var(--paper);
  opacity: 0.6;
}

/* No-hero pages: a solid brand bar sits behind the fixed (transparent) header. */
.navbg {
  position: sticky;
  top: 0;
  width: 100%;
  height: 100px;
  /* a slight gradient on the sky instead of flat teal */
  background: linear-gradient(to bottom, rgb(147, 231, 208), var(--color-bcr));
  mask-image: linear-gradient(#000, #000), url('assets/images/dunnerdale_skyline_slim.svg');
  mask-repeat: no-repeat, repeat-x;
  mask-position: center, right bottom;
  mask-size: cover, auto 51px;
  mask-composite: subtract;
  z-index: 55;
  pointer-events: none;
}

/* One page template serves both cases via the body class: the featured-image
   hero shows when there is one, the teal navbg "sky" cap when there isn't. */
body.no-hero .hero { display: none; }
/* No-hero: the navbg cap is the whole transition, so the hero's paper skyline/fade
   would double up — hide them. */
body.no-hero .skyline,
body.no-hero .fade { display: none; }
/* Has-hero: the navbg cap starts hidden and crossfades in on scroll (index.js),
   as a fixed overlay so it adds no flow space; .skyline/.fade fade out. */
body.has-hero .navbg { position: fixed; opacity: 0; }

/* The page title shows in the hero on has-hero pages, so the in-content title
   (page-sidebar) only appears when there's no hero. */
body.has-hero .content-title { display: none; }

/* WP injects a root block-gap — :where(.wp-site-blocks) > * { margin-block-start }
   — onto every top-level block. Our first in-flow chrome must sit flush; a class
   selector overrides the zero-specificity :where() rule with no !important. */
.hero,
.navbg { margin-block-start: 0; }

/* ---- Hero (chrome) --------------------------------------------------- */

.hero {
  position: sticky;
  top: calc(-85vh + 100px);
  display: block;
  height: 85svh;
  padding: 4rem var(--gutter);
  background-size: cover;
  background-position: center;
  color: #fff;
  z-index: 50;
  overflow: hidden;
  align-self: flex-start;
  /* Clip the hero's own bottom edge to the ridge (same mask as .navbg) so the
     page below meets it exactly — no white overlay to align. Its complement
     matches the navbg, so the crossfade has no step. */
  mask-image: linear-gradient(#000, #000), url('assets/images/dunnerdale_skyline_slim.svg');
  mask-repeat: no-repeat, repeat-x;
  mask-position: center, right bottom;
  mask-size: cover, auto 51px;
  mask-composite: subtract;
}
.hero-inner { position: absolute; left: 0; bottom: 3%; width: 100%; }
.hero-greeting {
  width: min(100%, var(--wide));
  margin: 0.5rem auto;
  padding: 3rem calc(3rem - 8px);
}
.hero h1 {
  font-size: var(--step-title);
  font-weight: bold;
  margin: 0;
  line-height: 1.0;
}
.hero-tagline {
  margin: 0.5rem 0;
  font-size: 1.2rem;
}

/* Featured-image hero (page/single covers): position the title like the
   front-page greeting — bottom-aligned, constrained to --wide, same padding —
   so a page with a hero and the front page share one title position. The cover's
   inner-container is the analogue of .hero-inner + .hero-greeting combined; the
   templates use layout:default so the title isn't capped to content width. */
.wp-block-cover.hero .wp-block-cover__inner-container {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(3% + 0.5rem); /* front page: .hero-inner bottom:3% + .hero-greeting margin */
  width: min(100%, var(--wide));
  max-width: none;
  margin-inline: auto;
  padding: 3rem calc(3rem - 8px);
}
/* CTA in a hero (page-join template) sits just below the title/strapline. */
.wp-block-cover.hero .cta { margin-top: 1.1rem; }

.hero .scroll-mask {
  position: absolute;
  inset: 0;
  background: #ffffff;
  opacity: 0;
  z-index: 3;
}

/* Front-page hero slideshow: a core Gallery block (.hero-gallery) restyled so its
   images stack full-bleed and slideshow.js cross-fades them — editors just pick
   pictures in the Gallery block, no markup. The greeting sits above via .hero-inner. */
.hero-gallery {
  position: absolute;
  inset: 0;
  display: block; /* override the gallery's flex grid layout */
  margin: 0;
  gap: 0;
}
.hero-gallery .wp-block-image {
  margin: 0;
  opacity: 0;
  transition: opacity 1s ease;
}
/* Core positions the gallery figures `relative` via
   `.wp-block-gallery.has-nested-images figure.wp-block-image` (0,3,1) — which
   outranks a plain `.hero-gallery .wp-block-image` (0,2,0), so without enough
   qualification the slides flow into a vertical stack. This selector is (0,4,1),
   so absolute wins and each slide lays over the hero box to cross-fade in place. */
.hero .hero-gallery.wp-block-gallery figure.wp-block-image {
  position: absolute;
  inset: 0;
}
/* No-JS fallback shows the first image; once slideshow.js adds .slides-js to the
   hero, visibility is handed to .is-active. */
.hero:not(.slides-js) .hero-gallery .wp-block-image:first-child,
.hero-gallery .wp-block-image.is-active {
  opacity: 1;
}
.hero-gallery .wp-block-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.hero-inner { z-index: 2; }

/* The paper skyline overlay is retired: the hero now masks its own bottom edge to
   the ridge (see .hero), so the page meets it with nothing to align. */
.skyline { display: none; }

/* ---- Body -----------------------------------------------------------
   Page bodies are core blocks; WP's constrained layout (theme.json
   contentSize/wideSize) owns inner width. <main> is only the layering
   context that lets content scroll up under the sticky skyline/fade. */

main {
  position: relative;
  z-index: 30;
  margin: 3em 0;
}

/* Marginalia secondary column */
.marginalia { padding-block: 1rem; }

/* Stick the sidebar column while scrolling. align-self stops the flex column
   stretching to the full row height (core sets .wp-block-columns{align-items:normal}),
   which would leave sticky no room to travel. Scoped to the column so the
   .bcr-next-event blocks inside don't also try to stick. */
.wp-block-column.marginalia {
  position: sticky;
  top: 100px;
  align-self: flex-start;
  order: 1; /* marginalia is FIRST in the DOM (so it can float-wrap on phones — see
               the @media below); flex `order` restores it to the right on desktop */
}
.marginalia h3 { font-size: var(--step-h3); margin: 1rem 0 0.25rem; }
.marginalia .next-event-label { font-size: 1rem; font-weight: normal; margin: 1rem 0 0.25rem; color: var(--muted); }
.marginalia .datemark {
  margin-left: -3.5rem;
}

/* ---- Footer (chrome) ------------------------------------------------- */

.site-footer {
  padding: 3rem var(--gutter) 2rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--muted);
}

/* Top region: brand · three link columns · search, wrapping down to a stack. */
.footer-inner {
  width: min(100%, var(--wide));
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 2.5rem 3rem;
  align-items: flex-start;
}

.footer-brand { flex: 1 1 80px; min-width: 0; }
.footer-logo { display: inline-block; }
.footer-logo img { width: 88px; height: auto; }
.footer-strap { margin: 0.75rem 0 1.1rem; font-size: 0.95rem; max-width: 22ch; }
.footer-contact { display: inline-flex; align-items: center; gap: 0.45em; font-size: 0.95rem; margin: 1em 0; color: var(--muted); }
.footer-contact .icon { width: 1.1em; height: 1.1em; flex: none; }

/* Reusable call-to-action pill (footer "Join the club", membership hero, …).
   Dark green + white text passes AA (same pair as the datemark). The arrow is
   an SVG sprite icon that nudges on hover. */
.cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.6rem 1.4rem;
  background: var(--accent-dark);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  text-decoration: none;
  border-radius: 999px;
  transition: filter 150ms ease, transform 150ms ease;
}
.cta .icon { width: 1.05em; height: 1.05em; transition: transform 150ms ease; }
.cta:hover { filter: brightness(1.12); transform: translateY(-1px); }
.cta:hover .icon { transform: translateX(3px); }
.cta:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Auto-fit grid so the link columns reflow (3 → 2 → 1) instead of overflowing
   on narrow screens; min-width:0 lets the flex children shrink to wrap. */
.footer-nav {
  flex: 2 1 320px;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 1.75rem 2rem;
}
.footer-col { min-width: 0; }

.footer-nav h2,
.footer-search-col h2 {
  margin: 0 0 0.9rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}

.footer-col ul { list-style: none; margin: 0; padding: 0; }
.footer-col li { margin: 0 0 0.55rem; }
.footer-col a,
.footer-copy a { color: var(--muted); text-decoration: none; }
.footer-col a:hover,
.footer-copy a:hover { color: var(--ink); text-decoration: underline; }

.footer-search-col { flex: 1 1 170px; min-width: 0; }
.footer-search label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--paper);
}
.footer-search input {
  border: 0;
  background: none;
  color: var(--ink);
  width: 100%;
  padding: 0;
  font-size: 0.9rem;
}
.footer-search input::placeholder { color: var(--muted); }
.footer-search .icon { width: 18px; height: 18px; flex: none; color: var(--muted); }
.footer-search-col .join-club {
  margin: 5rem 0 0;
}
/* Bottom bar: copyright/disclaimers on the left, colour control (and build
   version once JS fills it) on the right. */
.footer-bottom {
  width: min(100%, var(--wide));
  margin: 2.5rem auto 0;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  font-size: 0.85rem;
}
.footer-copy { margin: 0; }
.footer-bottom .theme-toggle { margin: 0; }
.app-version { margin: 0; font-size: 0.7rem; opacity: 0.6; }
.app-version:empty { display: none; }

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

/* Colour-mode control (footer). */
.theme-toggle {
  display: inline-flex;
  gap: 0.25rem;
  margin-top: 0.75rem;
}
.theme-toggle button {
  display: inline-flex;
  padding: 0.35rem;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: var(--radius);
  line-height: 0;
  cursor: pointer;
}
.theme-toggle button:hover { color: var(--ink); }
.theme-toggle button[aria-pressed="true"] {
  color: var(--paper);
  background-color: var(--ink);
}

a.facebook { color: var(--color-facebook); }
a.twitter { color: var(--color-twitter); }
a.instagram { color: var(--color-instagram); }

/* ====================================================================== */
/*  Hamburger button (hidden on desktop, revealed at the phone breakpoint) */
/* ====================================================================== */

.toggle-menu {
  display: none;                 /* shown in the phone @media below */
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  color: var(--ink);
  background: none;
  border: 0;
  cursor: pointer;
}

/* Morph the three lines into an X when the button reports itself open.
   transform-box:fill-box makes each line rotate about its own midpoint. */
.hamburger line {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform 200ms ease, opacity 150ms ease;
}
.toggle-menu[aria-expanded="true"] .hamburger .top    { transform: translateY(6px)  rotate(45deg); }
.toggle-menu[aria-expanded="true"] .hamburger .middle { opacity: 0; }
.toggle-menu[aria-expanded="true"] .hamburger .bottom { transform: translateY(-6px) rotate(-45deg); }

/* ====================================================================== */
/*  Responsive — desktop-first, content-driven breakpoints                 */
/* ====================================================================== */

/* Phone: inline nav becomes a hamburger + full-screen overlay. */
@media (width <= 40rem) {
  .toggle-menu { display: inline-flex; z-index: 220; }
  a.site-brand { z-index: 210; }

  .site-nav {
    position: fixed;
    inset: 0 0 15% 0;
    z-index: 200;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem;
    background: linear-gradient(to bottom, rgb(147, 231, 208), var(--color-bcr));
    transform: translateY(-100%);
    pointer-events: none;
    transition: transform 400ms ease;
    mask-image: linear-gradient(#000, #000), url('assets/images/dunnerdale_skyline_slim.svg');
    mask-repeat: no-repeat, repeat-x;
    mask-position: center, right bottom;
    mask-size: cover, auto 51px;
    mask-composite: subtract;
  }
  .site-nav .mobile { display: block; }
  .site-nav img.logo { width: 40%; margin: 1rem auto; }
  .site-nav a.nav { color: var(--paper); font-size: var(--step-h2); opacity: 1; }
  .site-nav span.socials { margin: 2rem auto; }
  .site-nav .theme-toggle { display: inline-flex; margin: 2rem auto 4rem; position: absolute; bottom: 0; }
  .site-search { z-index: 240; }

  .skyline {
    -webkit-mask-size: cover;
            mask-size: cover;
  }

  .marginalia .datemark {
    margin-left: 0;
  }

  /* Marginal events on phones: the content templates (front-page / page-sidebar)
     put the marginalia column FIRST in the DOM, so here we drop flex — float is
     ignored on flex items — and float the minimised card right; the body text then
     flows around it. Scoped to :first-child so it only fires on those reordered
     templates, not the event templates where marginalia trails the content. */
  .wp-block-columns:has(> .marginalia:first-child) {
    display: flow-root; /* block layout + contains the float */
  }
  /* Core ships .wp-block-post-content{display:flow-root} (a BFC) to keep floats
     inside the content from escaping. But a BFC sits BESIDE an outside float rather
     than letting text wrap around it — so it would defeat the wrap. Drop to block,
     scoped to this reordered layout only. Safe: the columns flow-root above still
     contains any float within the content, so nothing escapes (which is why plain
     block shows no ill effects). */
  .wp-block-columns:has(> .marginalia:first-child) .wp-block-post-content {
    display: block;
  }
  .wp-block-column.marginalia:first-child {
    float: right;
    width: 5.5rem;
    margin: 0 0 0.5rem 1rem;
    position: static;   /* not sticky on phones */
    padding: 0;
  }
  /* Bare minimum: show only the 'next social run' card (hide the race card + the
     "more events" note). Target children of the template-part wrapper, not the
     wrapper itself, so the card stays visible. */
  .marginalia:first-child .wp-block-template-part > :not(.bcr-next-event--run) {
    display: none;
  }
  /* Reorient that card: datemark on top, text beneath, narrow + centred. */
  .marginalia:first-child .bcr-next-event--run {
    font-size: 0.8rem;
    line-height: 1.3;
    text-align: center;
  }
  .marginalia:first-child .bcr-next-event--run .datemark {
    display: block;
    width: 3rem;
    float: none;
    margin: 1rem auto 0.5rem;
  }
  .marginalia:first-child .bcr-next-event--run p {
    overflow: visible;
    margin: 0;
  }
  .marginalia:first-child .bcr-next-event--run a {
    color: var(--ink);
    font-weight: bold;
    text-decoration: none;
  }
  .marginalia:first-child .bcr-next-event--run span.detail {
    display: none;
  }
  .toggle-menu[aria-expanded="true"] ~ .site-nav {
    opacity: 0.95;
    transform: translateY(0);
    pointer-events: auto;
  }

  /* Lock the page behind the open overlay. */
  body:has(.toggle-menu[aria-expanded="true"]) { overflow: hidden; }
}

/* Honour reduced-motion for the menu slide + icon morph. */
@media (prefers-reduced-motion: reduce) {
  .site-nav,
  .hamburger line { transition: none; }
}
