/* ============================================================
   FOCUS SYSTEM — what a keyboard user sees, in the site's own idiom
   (task 3124)
   ============================================================

   Martien, 10-09:

     "hoe wil je dit zichtbaar maken? en op pc/laptop vind ik het
      vreselijk, zon blok om je focus heen. maar op mobiel is het vast
      handig"

   Two things in that sentence, and they pull in opposite directions
   only until you know what :focus-visible does.

   WHAT HE WAS LOOKING AT was not a design decision. Roughly two thirds
   of the focusable elements on this site had no focus rule at all, so
   the browser drew its own: Chrome's white-on-black double ring, a hard
   rectangle that ignores the page entirely. That is the "blok" — nobody
   chose it, it was the fallback.

   :focus-visible IS THE ANSWER TO THE PC HALF. It paints only when the
   browser judges that a visible indicator is wanted, which in practice
   means keyboard and assistive-tech navigation. Click a button with a
   mouse and nothing appears. So on a laptop, driving with a trackpad,
   he will not see any of this — which is the point.

   AND IT CORRECTS THE MOBILE HALF. Touch does not raise :focus-visible
   either, so this is not "handig op mobiel"; on a phone it is invisible
   too. The people it is for are keyboard users, screen-reader users, and
   anyone with a motor impairment who cannot aim a pointer. Mobile gains
   nothing here and loses nothing.

   THREE SHAPES, chosen by Martien from four options ("site-eigen
   idioom"): the site already says "this is live" in one visual language,
   the gold hairline, and focus should speak it rather than import a
   generic ring.

     fields    a 2px gold line under the field, the same statement
               .bi-search__bar::after already makes when the big search
               input wakes up (main.css:3077)
     buttons   a 2px gold ring at 3px offset, drawn OUTSIDE the button
               and deliberately NOT the hover fill
     links     the gold underline at 2px, 4px clear of the text

   WHY THE BUTTON RING DOES NOT FILL. Before this file, buttons.css:155
   read `.bi-cta:hover, .bi-cta:focus-visible` — one rule, both states.
   A hovered button and a keyboard-focused button were pixel-identical,
   so tabbing through a group told you nothing a mouse had not already
   said, and on a page where the pointer happens to rest on a button you
   could not tell which one the keyboard was on. Hover is "your pointer
   is here"; focus is "your next Enter lands here". Different facts,
   different marks. That coupling is removed in this commit.

   HOW IT ATTACHES — this file is a floor, not a ceiling. Every selector
   here is deliberately low specificity (one element or one class), and
   the sheet loads last. The 28 bespoke focus rules that already existed
   — the hero's inset ring, the lightbox arrows, the dashboard tabs —
   all outrank it and keep winning. This fills the two thirds that had
   nothing, and standardises the shape of what it fills.

   NOT IN SCOPE: the wp-admin login screen. It has its own inline
   stylesheet in functions.php and never loads theme CSS, so its focus
   rule is fixed there instead of here.
   ============================================================ */

/* --bi-focus-w and --bi-focus-offset live in tokens.css (3128), with the
   rest of the measurements. One width for all three shapes: buttons already
   share a 2px border (--bi-btn-bw), so a 2px focus mark sits in the same
   weight class instead of reading as a second, thinner system, and the 3px
   offset puts the ring far enough off the box that it is clearly a separate
   mark and not a border that changed colour. */

/* ── The floor ─────────────────────────────────────────────────────────
   Everything focusable, including the things this file does not name:
   [tabindex] wrappers, summary elements, iframes, video controls, and
   whatever gets added next year. If a component wants something else it
   only has to be more specific than a bare pseudo-class, which every
   existing focus rule on this site already is.

   This is the rule that replaces Chrome's double ring, so it is also
   the one that has to be visible against every background the site
   uses. Gold on the navy ground clears the 3:1 non-text contrast
   requirement with room to spare; the browser default did not, on the
   full-bleed photography. */
:focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: var(--bi-focus-offset);
}

/* ── Fields ────────────────────────────────────────────────────────────
   The gold line under the field, which is what the big search input has
   always done. The line is a box-shadow rather than a border so nothing
   reflows by 2px at the moment of focus, and it hugs the bottom edge
   rather than ringing the box: a text field is a place you write on a
   line, and that is the shape the site already uses to say so.

   The border goes gold at the same time. Most of these fields did that
   already on plain :focus; stating it here means the ones that did not
   now match, and the ones that did are unaffected. */
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 var(--bi-focus-w) 0 0 var(--gold);
}

/* Checkboxes and radios are not lines you write on. They keep the ring. */
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: var(--bi-focus-offset);
  box-shadow: none;
}

/* Neither is a file picker or a colour swatch — both render as a button
   inside the input, so an underline sits under the wrong thing. */
input[type="file"]:focus-visible,
input[type="color"]:focus-visible,
input[type="range"]:focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: var(--bi-focus-offset);
  box-shadow: none;
}

/* An <input type="submit|button"> is a button wearing an input's tag. It
   follows the button rule below, not the field rule above. Defensive: every
   submit on the public site is a real <button> today (front-page.php:1350,
   page-propose.php:576, page-contact.php:118). Kept so the next one that
   is not does not silently get an underline.
   No `border-color` reset here on purpose. The obvious one, `inherit`,
   would sit at (0,2,1) and outrank .bi-cta's own border colour, so a
   focused CTA would have had its hairline redefined by a rule about input
   elements. Leaving it alone costs a gold border the button did not ask
   for; overriding it would have cost the button system's control of its
   own edge. */
input[type="submit"]:focus-visible,
input[type="button"]:focus-visible,
input[type="reset"]:focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: var(--bi-focus-offset);
  box-shadow: none;
}

/* The register's own search input is the field this idiom was copied
   FROM, and it already animates: .bi-search__bar::after grows a gold
   hairline to full width on :focus-within (main.css:3077). Left alone it
   would draw that line and this file would stack a second, thicker one
   1px below it. The animated original wins; this rule steps aside.

   The ONE exemption. The nav overlay's search input looks like it should
   be a second — same shape, same borderless-with-a-bottom-rule
   construction — but it has no ::after and no :focus-within rule, so
   exempting it would have left it with a 1px border going from white-20%
   to gold and nothing else. It takes the standard underline. */
.bi-search__input:focus-visible {
  box-shadow: none;
}

/* ── Links ─────────────────────────────────────────────────────────────
   A ring around a word in the middle of a sentence is the "blok" Martien
   objected to, and it is genuinely ugly: it boxes a shape that is not a
   box, and it breaks across lines when the link wraps. Text links get
   the underline instead — same gold, same 2px, held 4px clear so it
   reads as a mark on the link rather than part of the type.

   4px rather than the ring's 3px on purpose: an outline is measured from
   the box edge, an underline from the baseline, and 4px is where the two
   look like the same distance.

   [href] is load-bearing, not decoration. A plain `a:focus-visible` sits
   at (0,1,1), which loses to any `.something a { text-decoration: none }`
   in the theme — and there are 88 text-decoration:none declarations
   across these stylesheets. The underline would have silently failed on
   exactly the links that are styled most. With [href] the rule is (0,2,1)
   and beats all 88, checked by walking every one of them rather than
   spot-testing. It is also the honest selector: an <a> without href is
   not focusable in the first place. */
a[href]:focus-visible {
  outline: none;
  text-decoration: underline;
  text-decoration-color: var(--gold);
  text-decoration-thickness: var(--bi-focus-w);
  text-underline-offset: 4px;
}

/* ── ...except the links that are not text ─────────────────────────────
   An underline needs a baseline to sit on. A link that wraps a photo, a
   whole card, or a bare icon has no text to underline, so the rule above
   would leave it with no focus mark at all — the exact failure this task
   exists to fix, reintroduced one rule later. Those get the ring back.

   Split across three rules on purpose, not merged into one selector
   list: CSS drops an ENTIRE rule when any selector in its list fails to
   parse, so putting :has() next to .bi-cta would take the button rule
   down with it on any engine that does not support :has(). Separated,
   the worst case is that one category degrades. */
a.bi-cta:focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: var(--bi-focus-offset);
  text-decoration: none;
}

/* The per-slide overlay link on the type and category sliders: its text
   is a label sitting on a photo, so the underline would land on the
   image rather than under the link. The only named card link that needed
   listing — .bi-fam-card__link and .bi-photo-expand already carry their
   own focus rules (main.css:12644, lightbox.css:157), and both use an
   INSET ring because the link fills its container and an outward one
   would be clipped. Naming them here would have overridden that with a
   +3px offset and quietly broken two things this task set out to fix. */
a.bi-slider__explore:focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: calc(var(--bi-focus-offset) * -1);
  text-decoration: none;
}

/* Anything wrapping an image or an icon, named or not. :has() is
   Baseline in every browser this theme targets; where it is missing the
   link keeps the underline, which is a worse mark rather than no mark.
   [href] again, and for a second reason here: :has() takes the
   specificity of its argument, so `a:has(> img):focus-visible` is only
   (0,1,2) and would have lost to the underline rule above it. */
a[href]:has(> img):focus-visible,
a[href]:has(> svg):focus-visible,
a[href]:has(> picture):focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: var(--bi-focus-offset);
  text-decoration: none;
}

/* ── Buttons ───────────────────────────────────────────────────────────
   The ring, outside the box, in the same 2px the button's own border
   uses. What it deliberately does NOT do is fill: see the header. A
   focused solo button stays an outline with white letters and gains a
   gold ring; hovering it still fills gold, and focusing a hovered button
   now shows both marks at once, which is the honest reading.

   The primary is already solid gold, so its ring is the only thing that
   could show — hence the 3px offset, which keeps gold-on-gold from
   touching. */
.bi-cta:focus-visible,
button:focus-visible,
[role="button"]:focus-visible,
summary:focus-visible {
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: var(--bi-focus-offset);
}

/* ── Skip link (task 3187) ────────────────────────────────────────────
   The first focusable element in the document (header.php, right after
   wp_body_open()), targeting #bi-page-content — the shared content
   wrapper that exists on every page, including the front page, which
   skips the <main> tag other pages get. Off-screen by default via a
   negative top rather than display/visibility, so it stays in the tab
   order and only becomes visible once it is actually focused. Same gold
   ring the rest of this file uses so it reads as this site's own focus
   language rather than a bolted-on generic pattern. */
.bi-skip-link {
  position: fixed;
  top: -100%;
  left: 0;
  z-index: 1000;
  padding: .75em 1.25em;
  background: var(--bg);
  color: var(--gold);
  font: inherit;
  text-decoration: none;
}
.bi-skip-link:focus-visible {
  top: 0;
  outline: var(--bi-focus-w) solid var(--gold);
  outline-offset: calc(-1 * var(--bi-focus-w));
}
/* The skip target itself: landing here is a scroll jump, which is
   already the visible signal. A gold ring around the entire page's
   content — often several screens tall — would be the "blok" this
   file exists to avoid. */
#bi-page-content:focus-visible {
  outline: none;
}

/* ── Windows high-contrast ─────────────────────────────────────────────
   Forced-colors mode replaces our palette wholesale, and var(--gold)
   resolves to a colour the user did not choose. Hand the decision back
   to the system keyword and drop the underline, which forced-colors
   draws in its own way. */
@media (forced-colors: active) {
  :focus-visible,
  a:focus-visible,
  input:focus-visible,
  textarea:focus-visible,
  select:focus-visible,
  .bi-cta:focus-visible,
  button:focus-visible {
    outline: 3px solid Highlight;
    outline-offset: 2px;
    box-shadow: none;
  }
}
